私はこのコードを少し前に書いていますが、今は新しいプロジェクトで復活していますが、それはうまくいかないと思われます。ハッシュを検証する。Blowfishの暗号化 - ハッシュが作成されても検証されません
最初のpasswordEncrypt()関数を呼び出すと、次の2つの関数が呼び出されます。
ログインしようとすると、ログインする代わりにcheckPassword()関数が呼び出され、 'yes'が返される代わりに、 'no'と表示されるセクションに移動します。
新鮮な目が見える場合は、事前に感謝してください!
// Encrypt user password
function passwordEncrypt($password) {
// set the salt
$salt = substr(md5(time()), 0, 22);
// encrypt using blowfish with a load of 10
$password = crypt($password, '$2a$10$' . $salt);
// return the encrypted hash
return $password;
}
/*
Check password function when logging in
first we select the password from the supplied username from the database
// get the row and set the hash to the currect password from the database
//run the salts etc and check to see if the passwords match
*/
function checkPassword($userName, $password, $db){
$sql = 'SELECT password FROM users WHERE userName = :userName';
$stmt = $db->prepare($sql);
$stmt->bindValue(':userName', $userName, PDO::PARAM_STR);
$stmt->execute();
$numRows = $stmt->rowCount();
if ($numRows > 0) {
$row = $stmt->fetch();
$hash = $row['password'];
// run the hash function on $password
$fullSalt = substr($hash, 0, 29);
$new_hash = crypt($password, $fullSalt);
// Check that the password matches
if($hash == $new_hash) {
echo 'yes';
exit;
return true;
} else {
echo 'no';
exit;
return false;
}
} else {
echo 'way';
exit;
return false;
}
}
私は、パスワードを登録し、それを試してみました、これはそれが
パスワード返すものですしている:$ 2aに入力された$ 10 $ 023d3086e8462207a1fecueWH4Ub40MWbQJ7F9 :$ 2A $ 10 $ 023d3086e8462207a1fecueWH4Ub40MWbQJ7F9hapWU3lYxlg3AAa 何
だから、それはありませんhapWU3lYxlg3AAaの追加
パスワード列の長さとハッシュ文字列の長さは何ですか? –
btw、あなたの出口はあなたのリターンをキャンセルしています。 –
あなたが誰かにpingする方法を知っていれば、良い。あなたの質問は魔法の答えを与える資格はありません。 –