这存储在数据库中。如何将此演示密码发送给我的用户?我不能将这个($ 2y $ 10 $ Zjk5YzQ4ZTlhMzNlNTUzMO3Wnm1FqXmAb6/4DmyptNGoEdWGLwls。)转换为普通文本。使用blowfish发送忘记密码的电子邮件
有没有解决方法?我也无法发送随机密码。
demo = $2y$10$Zjk5YzQ4ZTlhMzNlNTUzMO3Wnm1FqXmAb6/4DmyptNGoEdWGLwls.
这里有一些功能我用密码检查和生成:
function password_encrypt($password) {
$hash_format = "$2y$10$"; // Tells PHP to use Blowfish with a "cost" of 10
$salt_length = 22; // Blowfish salts should be 22-characters or more
$salt = generate_salt($salt_length);
$format_and_salt = $hash_format . $salt;
$hash = crypt($password, $format_and_salt);
return $hash;
}
function generate_salt($length) {
// Not 100% unique, not 100% random, but good enough for a salt
// MD5 returns 32 characters
$unique_random_string = md5(uniqid(mt_rand(), true));
// Valid characters for a salt are [a-zA-Z0-9./]
$base64_string = base64_encode($unique_random_string);
// But not '+' which is valid in base64 encoding
$modified_base64_string = str_replace('+', '.', $base64_string);
// Truncate string to the correct length
$salt = substr($modified_base64_string, 0, $length);
return $salt;
}
function password_check($password, $existing_hash) {
// existing hash contains format and salt at start
$hash = crypt($password, $existing_hash);
if ($hash === $existing_hash) {
return true;
} else {
return false;
}
}
我没有看到你问的实际问题。 “演示密码”是什么意思? –
如果用户忘记了自己的密码,那么他们应该被发送一个链接,其中包含一个随机生成的令牌(限定时间和仅限一次使用),可用于获取可以设置新密码的表单。您不应该将散列的密码发送给用户。 – Quentin
但这是blowfish –