php - Validating passwords with random salts -
i have been trying learn hashes , salts stored in users table withing mysql db. through storing them can't seem wrap head around how validate when user logs in.
have looked through , seen storing salt , hash seperately , together. salt producing random.
any ideas?
have posted code.
<?php $password = 'passwordwhatever'; //generate salt function gen_salt() { $salt = uniqid(mt_rand(), true) . sha1(uniqid(mt_rand(), true)); $salt = crypt('sha512', $salt); return $salt; } //generate hash function gen_hash($salt, $password) { $hash = $salt . $password; for($i = 0; $i < 100000; $i++) { $hash = crypt('sha512', $hash); } $hash = $salt . $hash; return $hash; } $password = gen_hash(gen_salt(), $password); echo $password; ?>
as long produce same salt, shouldn't matter much. store in db, in configuration, long can it. effort of reversing sha512 hash high unless you're pentagon, nobody bother. point want able repeat hash same salt can sure input same without having store sensitive input. if makes sense.
Comments
Post a Comment