Jump to content

Recommended Posts

Hi Friends,

 

I Created a registration page and a login form. Which are working fine.

 

Now i want to validate password field.

That is if some one given password  as Sunil7 while registering.

"S" is uppercase and all other are lowercase now in my code i am not able to check this one

below is my simple code

<?php
require "config.php";  

$username=$_REQUEST["uname"];
$password=$_REQUEST["password"];



$sql="SELECT * FROM users WHERE username='$username' and password='$password'";
$result=mysql_query($sql);

 

how to validate this case sensitivity. if he gives password as Sunil7 then only its has to login not in the case if he give sunil7

 

Link to comment
https://forums.phpfreaks.com/topic/135368-validating-login-form/
Share on other sites

I would store the password in the DB as an MD5 hash. That will validate against case sensitivity and secure peoples passwords. You would have to change to when the password is inserted in the db it get's hashed using the md5 function to allow this.

 

<?php
require "config.php";  

$username=$_REQUEST["uname"];
$password=md5($_REQUEST["password"]);



$sql="SELECT * FROM users WHERE username='$username' and password='$password'";
$result=mysql_query($sql);
?>

 

If you do not want to hash the password, then this would work:

 


[code]
<?php
require "config.php";  

$username=mysql_real_escape_string($_REQUEST["uname"]);
$password=$_REQUEST["password"];



$sql="SELECT password FROM users WHERE username='$username' LIMIT 1";
$result=mysql_fetch_assoc(mysql_query($sql));
if (is_array($result)) {
    if ($result['password'] != $password) 
         die("Invalid username or password");
}else {
     die("Invalid username or password");
}
?>

 

I almost always store my passwords as an MD5 hash in the DB, securer and makes it easier to check against case sensitivity.

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.