mrkfox Posted May 10, 2009 Share Posted May 10, 2009 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 More sharing options...
gaza165 Posted May 10, 2009 Share Posted May 10, 2009 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 Link to comment https://forums.phpfreaks.com/topic/157572-solved-md5-producing-different-hashes/#findComment-830935 Share on other sites More sharing options...
mrkfox Posted May 10, 2009 Author Share Posted May 10, 2009 Ha Ha thank you very much. What a stupid mistake by me it was set to VARCHAR(20) Well thanks anyway Link to comment https://forums.phpfreaks.com/topic/157572-solved-md5-producing-different-hashes/#findComment-830936 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.