saifi4u Posted March 7, 2007 Share Posted March 7, 2007 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 Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 7, 2007 Share Posted March 7, 2007 <?php $str = "Mary Had A Little Lamb and She LOVED It So"; $str = strtolower($str); echo $str; // Prints mary had a little lamb and she loved it so ?> Quote Link to comment Share on other sites More sharing options...
saifi4u Posted March 7, 2007 Author Share Posted March 7, 2007 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 Quote Link to comment Share on other sites More sharing options...
ylkien Posted March 7, 2007 Share Posted March 7, 2007 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 Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted March 7, 2007 Share Posted March 7, 2007 Just use the identical with operator: === Example: <?php $var1 = "Hello"; $var2 = "hello"; var_dump($var1 === $var2); //outputs: bool(false) ?> Quote Link to comment Share on other sites More sharing options...
saifi4u Posted March 8, 2007 Author Share Posted March 8, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.