我使用下一个代码来注册用户:名称和密码,存储密码我使用 crypt() 和河豚,它可以工作,但我不知道如何在登录表单中解密密码
$user = $_POST['user'];
$password = $_POST['pass'];
function cryptPass($input, $rounds = 5){
$salt = "";
$saltChars = array_merge(range('A','Z'), range('a','z'), range(0,9));
for($i=0; $i < 22; $i++) {
$salt .= $saltChars[array_rand($saltChars)];
}
return crypt($input, sprintf('$2y$%02d$', $rounds) . $salt);
}
$password_hash = cryptPass($password);
$cSQL = "INSERT INTO USERDB (NAME, PASS) VALUES(?,?)";
$stmt = $db->prepare($cSQL);
$stmt->bind_param('ss', $name, $password_hash);
$stmt->execute();
$stmt->close();
这是解密密码的功能,但它不起作用,我的错误在哪里?
$user = $_POST['user'];
$password= $_POST['pass'];
function cryptPass($input, $rounds = 6)
{
$salt = "";
$saltChars = array_merge(range('A','Z'), range('a','z'), range(0,9));
for($i=0; $i < 22; $i++) {
$salt .= $saltChars[array_rand($saltChars)];
}
return crypt($input, sprintf('$2x$%02d$', $rounds) . $salt);
}
$inputPass = $password;
$pass = $password;
$hashedPass = cryptPass($pass);
$passcrypt = crypt($inputPass, $hashedPass);
$stmt = $db->prepare("SELECT NAME, PASS
FROM USERDB
WHERE NAME = ? AND PASS =?");
$stmt->bind_param('ss', $user, $passcrypt);
$stmt->execute();
$stmt->close();