Tell me more ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

maybe I have the concept of hashing wrong, but when I hash my passwords and salt them I get one string, and when I go to log in the newly signed up user I apply the same method on the password they used to sign up to log in. If I understand hashing right, shouldn't the hashs be exactly the same when I go to compare them? It always turns out that they are different so the user can't ever log in.

here is the method I'm using for hashing

$pass = "password"
$salt = "key";
$newpass = md5($key.$pass);

and then when I go to access the password I just take the inputed password apply the same method to it and then check if the one in the database is the same as the generated one, but they aren't ever the same as each other, the one in the database is always the same and the one generated is always the same but they aren't ever equal.

share|improve this question
Same inputs => same outputs, therefore the inputs differ. – mgkrebbs Aug 15 '12 at 19:01
As mgkrebbs says. Check your character encodings. – w3d Aug 15 '12 at 20:39
On-topic in stackoverflow.com – Jordan Aug 15 '12 at 21:20
I read that you already solved your problem, nevertheless i would recommend, that you read a bit about properly hashing passwords. Today it's recommended to use bcrypt, with a unique salt for each password. Using the bcrypt hash can be even easier than your example with the MD5() function, i tried to explain the important points in this article. – martinstoeckli Aug 16 '12 at 8:09
yeah I've multi hashed my passwords with a few of the newer functions – Brendan Webster Aug 16 '12 at 15:40

closed as off topic by John Conde Aug 15 '12 at 15:53

Questions on Webmasters Stack Exchange are expected to relate to webmastering within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

Browse other questions tagged or ask your own question.