Jump to content

[SOLVED] MD5 producing different hashes


mrkfox

Recommended Posts

Hi, I have a simple login system for my website which works perfectly without encryption. Now i treid adding encryption to the user password during registartion and everything worked fine and the encrypted password was correctly saved within my database. Heres the code i used for that:

$encrypted = md5($password);

 

Now when it comes to login I'm having a problem. Once the user has entered their password on a form the password gets encrypted and then checked against the one on the database. This is the code that does this:

$encrypted_pass = md5($password);
         $query = "SELECT username FROM users WHERE username='$username' and password='$encrypted_pass'";

 

Now the probelm is that when i encrypt the password the user has entered into the password field i get a different result to when the password is encoded upon registration. Here an example: (the letter a being encoded)

 

Registration encryption:  0cc175b9c0f1b6a831c3

Sign in encryption:        0cc175b9c0f1b6a831c399e269772661

 

As you can see the first 20 chars are all the same but then the login encryption has 12 extra. I have no idea why this is happening. Any help would be greatly appreciated.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/157572-solved-md5-producing-different-hashes/
Share on other sites

From my knowledge of MD5 encryption it always encrypts to a password 32 characters long.... in your database structure is your password field VARCHAR(32) in your registration table???

 

If your registration password field is 20 chars, you need to change it to hold 32 chars

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.