Jump to content

Case sensitive PHP login


saifi4u

Recommended Posts

Hi to all........I have a PHP login page that match the values from a table in mysql table....All the values inserted in MYSql table are of lower case..........But I can login with uppercase also..........

 

I need my login page case sensitive............the code is as under:

 

<?php 
session_start(); 
$errorMessage = ''; 
if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) { 
     
    $userId   = $_POST['txtUserId']; 

    $password = ($_POST['txtPassword']); 
     require_once("db_fns.php");
db_connect();

    $sql = "SELECT *  
            FROM adminuser
            WHERE username = '$userId' AND password = '$password'"; 
     
    $result = mysql_query($sql) or die('Query failed. ' . mysql_error());  

$row=mysql_fetch_array($result);
$admin=$row['username'];
   // print $admin;
    if (mysql_num_rows($result) == 1) { 

   	$_SESSION['db_is_logged_in'] = true; 

	$_SESSION['admin']=$admin;
		      
    	header('Location: main.php'); 
        exit; 
    } else { 
        $errorMessage = 'Sorry, wrong user id / password'; 

    } 
     
} 
?> 

 

thanks

Link to comment
Share on other sites

Actually I do not need to convert my string to lower case.

 

I need that if password is in lower case then it should not be login with uppercase password string.......

 

this time I enter my password either in lower case or upper case I am able to login which is not good...............

 

password should must be Case sensitive..........for secure login

Link to comment
Share on other sites

I see 2 says of doing this

 

1) Modify MYSQL table

taken from this site http://dev.mysql.com/doc/refman/5.0/en/case-sensitivity.html. If you want a column always to be treated in case-sensitive fashion, declare it with a case sensitive or binary collation. See Section 13.1.5, “CREATE TABLE Syntax”.

 

2) Extract data from database, then use PHP to compare

Link to comment
Share on other sites

Thank u very much ylkien.........

 

I was searching for the solution you told..............my problem has been solved..........

 

But I noticed that one thing should must be clear.......I create table with the sentax:

 

mysql> create table adminuser (username VARCHAR(10), password varchar(10)) CHARACTER SET latin1 COLLATE latin1_bin;

 

 

this solved my case sensitive login problem..........But both the fields "Username" and "Password" are now case sensitive........

 

What should I do If I want to make my "Password" field case sensitive and "Username" field still not case sensitive.

 

thanks

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.