php - PHPass refuses to check hashes -
include 'lib/php/passwordhash.php'; $hash = $_get['hash']; $pass = $_get['pass']; $hasher = new passwordhash(8, false); $pass = $hasher->hashpassword($pass); echo "original:<br>" . $pass . "<br>"; $checked = $hasher->checkpassword($pass, $hash); echo "hashed:<br>" . $checked . "<br>"; echo "<br>"; echo "are equal? <b>"; if($pass == $checked){ echo "yep!</b>";} else{ echo "nope. </b>"; } the incredibly simple piece of code above not work @ intended. yes, pass variable gets hashed , outputted correctly, checkpassword() fails output @ all. have tested simple word "hello" , inserted them directly function (e.g. checkpassword('$2...', '$2...'); , still outputs nothing.
i'm running on xampp windows, , i've been forced conclude must problem. used code rather actual project remove database factor, , found issue.
try restrain yourselves vomiting @ uglyness of code, desperate attempt work.
if running code you'll need place both 'pass' , and 'hash' variable in url test this. i've made terrible mistake somewhere, i'm not confident @ blaming environment.
edit:
i used code below generate initial variable use in url
$hash = $_get['hash']; $hasher = new passwordhash(8, false); $hash = $hasher->hashpassword($pass); echo $hash;
you're using checkpassword incorrectly. first argument should plain text; second hash, according documentation. setting $pass hashed value, using first argument in checkpassword anyway.
corrected code (untested):
include 'lib/php/passwordhash.php'; $hash = $_get['hash']; $pass = $_get['pass']; $hasher = new passwordhash(8, false); // delete line: $pass = $hasher->hashpassword($pass); echo "original:<br>" . $pass . "<br>"; $checked = $hasher->checkpassword($pass, $hash); echo "hashed:<br>" . $checked . "<br>"; echo "<br>"; echo "are equal? <b>"; if($pass == $checked){ echo "yep!</b>";} else{ echo "nope. </b>"; } p.s. i'm not sure why trying value of $hash $_get. if let user specify both password , hash, can fool application granting access. i'm assuming test , use database or other secure storage in real app.
Comments
Post a Comment