简体   繁体   中英

Identical Phpass code returning different results with CheckPassword

I am using Phpass to hash the passwords of my users. The creation and hashing of the password - fine. The checking of the password when logging in - fine.

The checking of the old password when changing it to a new one though - always returns false!

It is basically the same code but it never returns true, even when the password is correct. I have tried just checking the password outright by typing a password and pasting its hash into the function instead of calling it from the database and the input form but that still returns false.

Here is the login code which works:

$user = $query->fetch(PDO::FETCH_ASSOC);

$t_hasher = new PasswordHash(8, FALSE);
$check = $t_hasher->CheckPassword($password, $user['password']);

if (!$check) { die("failed"); }
else { ... log them in etc.

And here is the change password check, which doesn't work:

$user = $query->fetch(PDO::FETCH_ASSOC);

$t_hasher = new PasswordHash(8, FALSE);
$check = $t_hasher->CheckPassword($oldpass, $user['password']);

if (!$check) { showMessage("Incorrect Password","Your password was not changed.","icon-lock", "warning"); }
else { ... change the password etc.

I am at a loss, as far as I can see there is no conceivable reason why this isn't working.

原来我是个笨蛋,忘了执行数据库查询更改密码。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM