Topic: Login: SHA1/MD5 passwords don't match (Read 2504 times)
Google dot what?
Posts: 2
16 credits Members referred : 0
« on: Feb 24, 2011, 08:05:01 pm »
I'm trying to create a User Login on my website using php/mySQL. When I create a new user, I send the password as a MD5 hash to my database. The problem is, when I try to login with the same password (again, hashed using MD5), the passwords don't match.
Here is my SQL code: for createUser.php:
Code:
INSERT INTO `Users` (`UserLogin`, `UserPass`) VALUES ('name', MD5('pwd'))
for login.php
Code:
SELECT * FROM `Users` WHERE `UserLogin` = 'name' AND `UserPass` = MD5('pwd')
I have tried entering this code directly into phpMyAdmin, with no results -- so it isn't a problem with my php code. I have also tried using SHA1 hashing.
What am I doing wrong?
Bill Cosby is my Father
Posts: 4
28 credits Members referred : 0
« Reply #1 on: Feb 27, 2011, 12:40:54 pm »
Hi,
the only reason I can imagine is that the `UserPass` column is not big enough to hold the hash.
For example if the is hash is 1234 but your column can only hold 123, the next time you'll compare the generated hash 1234 with 123 it won't match.
If changing that doesn't help, post your table structure.
Destructive
Google dot what?
Posts: 2
16 credits Members referred : 0
« Reply #2 on: Feb 27, 2011, 02:33:30 pm »
Quote
the only reason I can imagine is that the `UserPass` column is not big enough to hold the hash
Thanks, Destructive! That was exactly it. My UserPass was set as INT(16), and needed to be at least INT(32) to hold the hashed password.
Bill Cosby is my Father
Posts: 4
28 credits Members referred : 0
« Reply #3 on: Feb 27, 2011, 02:46:49 pm »
You're welcome. I'm glad I could help you.
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=11365