Jump to content

Password problem


wut

Recommended Posts

Having a little problem with passwords, they are stored clear text and not encrypted because its for an assignment and I need to prove in the write up that users can change their passwords.

 

Anyway when I register a user with a username and a password of say Password1, I can still login with PASSword1 or any other variation of upper and lower case characters!

 

This is my select statement:

$qry = "SELECT * FROM users WHERE username='$username' AND password='$password'";

 

Just wondering if there is anything that can be done to this, I read somewhere about using === but that doesn't seem to be fixing the problem, it just causes the query to fail!

Using MySQL if thats any help.

 

Thanks

Link to comment
Share on other sites

Alternately, you can just check if the passwords are the same using PHP. Setting the charset of your password field as non-ci (case-insensitive) would be ideal though.

 

<?php

$qry = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$result = mysql_query($qry);
if( $result == FALSE ) {
echo 'Could not execute query';
} else {
$data = mysql_fetch_assoc($result);
if(mysql_num_rows($result) < 1 || $data['password'] != $password ) {
	echo 'Could not find username/password combo.';
} else {
	echo 'Logged in successfully.';
}
}


?>

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.