幾天來我遇到了一個關(guān)于password_verify()的問題。在我的網(wǎng)址中輸入密碼失敗之前我沒有注意到這一點(diǎn)。解釋一下,我正在開發(fā)一個 Web 服務(wù),為了進(jìn)行身份驗證,我需要在請求 URL 中使用密碼和 ID。這是我的代碼 if ($stmt->prepare("SELECT hashedPWD FROM `user` WHERE `id` = ?")){ // Trying to get the hashed pwd stored in DB $stmt->bind_param("i", $id); $stmt->execute(); $stmt->bind_result($pwdHash); // $pwdHash contains the password hashed by password_hash() when the account was created $stmt->fetch(); $stmt->close(); }$password = "test"; // The password in URL which is the good one$isPwdGood = password_verify($password, $pwdHash);var_dump($isPwdGood); // returns true, seems good right there$password = "testtttttttttt"; // contains the real password with some others characters $isPwdGood = password_verify($password, $pwdHash);var_dump($isPwdGood); // returns also true這里的問題是,當(dāng)我想確認(rèn)我的客戶的身份時,我需要確保密碼是他給我的密碼,但是使用password_verify()我可以獲得一個包含真實(shí)密碼的錯誤密碼,并且它會起作用。
1 回答

慕哥6287543
TA貢獻(xiàn)1831條經(jīng)驗 獲得超10個贊
我沒有觀看創(chuàng)建帳戶的整個過程,應(yīng)該這樣做,因為我剛剛看到使用的函數(shù)是 crypt() 并且(我不知道為什么)它與以前的鹽和哈希值配合得不好密碼。
我嘗試切換到我向您展示的函數(shù),即password_hash(),它效果更好!
- 1 回答
- 0 關(guān)注
- 120 瀏覽
添加回答
舉報
0/150
提交
取消