PHPass的正确实现

2022-01-22 00:00:00 passwords php phpass

我正在使用 PHPass 在我的应用程序中存储用户密码,因为它比 md5 或 sha1 更安全.我有一个关于如何在密码中使用盐的问题.

I'm using PHPass to store users passwords in my application because it's more secure than md5 or sha1. I have a question about how I would use a salt with the passwords.

根据我收集的信息,当您插入用户时,我会这样使用它:

From what I gathered, I use it like this when you insert a user:

$pwdHasher = new PasswordHash(8, false);
$hash = $pwdHasher->HashPassword($input_password);

然后当您在登录时检查用户详细信息时,您会这样做:

and then when you check the users details on login, you do:

$pwdHasher = new PasswordHash(8, FALSE);
if ($pwdHasher->CheckPassword($input_password, $hash_from_db)) {
    echo 'password correct';
} else {
    echo 'wrong credentials';
}

但我没有看到任何使用盐的地方.根据我的阅读,我的用户表应该有一个额外的字段用于散列密码时使用的盐,但是 PHPass 的 CheckPassword 方法不需要盐?

But I see nothing there that uses a salt. From what I've read, my user table should have an extra field for a salt that is used when hashing the password, but the CheckPassword method of PHPass doesn't take a salt?

谢谢.

推荐答案

Phpass 在对密码进行哈希处理时添加盐,因此无需添加单独的盐并将其存储在数据库中.

Phpass adds a salt when it hashes the password so there's no need to add a separate salt and store it in your database.

相关文章