Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Password encryption problem 1

Status
Not open for further replies.

neilmurray

Technical User
Jan 18, 2005
32
GB
I am having a problem getting a password to agree with the encrypted one in mysql. here is my code

$num = mysql_num_rows($result);
if ($num == 1) //login name was found
{
$sql = "select loginName from Member
where loginName='$fusername'
and password=password('$fpassword')";
$result2 = mysql_query($sql)
or die("Couldn't execute query.");
$num2 = mysql_num_rows($result2);
if ($num2 > 0) //password is correct
{
$auth='yes';
$logname=$fusername;
$today = date("Y-m-d h:m:s");
$sql = "insert into Login (loginName,loginTime)
values ('$logname','$today')";
mysql_query($sql) or die("Can't execute query.");
header("Location: about.php");
}
else //password is not correct
{
unset($do);
$message="This is not the correct password, please try
again.<br>";
include("login_form.inc");
}

Its finding the login name but the passwords are not agreeing. I think it is encrypting it wrong

Neil.
 
Have you tried the same query from an mysql prompt?
The reason i ask is that i had the same problem, and it turned out to be a matter of field data types, and NOTHING to do with my coding in php. (D'Oh)
I had my password field in mysql set to type varchar(16). But an encrypted password is bigger than that.

It may not solve your problem, but since i wrestled with it for a few weeks i thought i'd share my experience!

;-)

Caff



 
1. The MySQL PASSWORD function uses MD5, which is a hashing algorithm, not an encryption.
2. How are the password originally created? Look at the code that writes them into the database. Prompt out the MD5 treated password and compare it (visually) with the content of the table contents.
 
Have you upgraded the mysql version lately? There are some changes in the way that password($pass) gets encrypted. I prefer to use the MD5 hashing to handle the passwords.

Bastien

Cat, the other other white meat
 
There are changes in the way mysql uses the password function , if you have upgraded versions tecently. Have you?

I prefer to use the md5 hashing to encrypt passwords.

Bastien

Cat, the other other white meat
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top