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
https://forums.phpfreaks.com/topic/41574-case-sensitive-php-login/
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

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

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.