3
成功驗證數據庫中存在用戶名後,我需要驗證密碼是否匹配。因此,我需要從數據庫中檢索哈希密碼,對吧?還是我有其他選擇?MySQL php使用另一列獲取列(使用用戶名獲取密碼)
我使用PHP 5.5 API bcrypt進行散列。當我從數據庫獲取密碼時,我的代碼會給我一個500內部服務器錯誤。我如何正確地做到這一點?
這裏是我的PHP代碼:
// If found username, check password, else respond invalid username
if($countRows!==0){
// Get hash from database
// Prepare statement
$stmt = $conn->prepare('SELECT password FROM users WHERE username = ?');
// Bind
$stmt->bind_param('s', $ps_username);
// Set Parameters
$ps_username = $username;
// Execute
$hash = $stmt->execute();
// Check password
if (!password_verify($password, $hash)) {
if($error != ""){
$error .= '<br>';
}
$error .= 'The user or password you entered do not match, please try again.';
}
else {
echo 'OK';
// Session start
// Redirect user to profile/homepage
}
}
而且可以有人推薦的東西,我可以學習SQL命令?我找不到一個好地方。
好的,謝謝。這意味着我準備好的陳述是正確書寫的。這很好聽,因爲我看到的教程並沒有真正教會我如何使用這些命令,所以我只是假設這些命令可以混合在一起。 – J13t0u