我想創建一個登錄頁面,我遇到了一些麻煩。即使我知道在我的.txt文檔中有正確的密碼,但我無法讓此代碼不返回錯誤(雖然它只是散列)。沒有SQL數據庫的PHP登錄問題
這是我的PHP文件,我不能停止獲取不返回False:
<?php
$file1 = 'userlist.txt';
$file2 = 'passlist.txt';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$user = trim($_POST["usermail"]);
$pass = trim($_POST["password"]);
}
$hashedPass = "";
$arr1 = file($file1);
$arr2 = file($file2);
$userKey = array_search($user, $arr1);
if ($userKey != false) {
reset($arr2);
for ($x = 0; $x <= $userKey; $x++) {
next($arr2);
if ($x == $userKey) {
$hashedPass = current($arr2);
}
}
echo $hashedPass;
}
if (password_verify($pass, $hashedPass)) {
header("Location: worked.html"); //change this to direct user to market
}
else {
/*header("Location: index.html"); //change this to direct user back to login page with error prompt*/
print $pass;
print $hashedPass;
echo '<br>Invalid pass.';
return false;
}
?>
而且,如果你能想到的任何東西我應該在我的代碼,請讓我知道。
非常感謝。
編輯:現在更新我的代碼。仍然返回False。
所以我應該這樣做: if(password_verify($ pass,$ hashedPass.unHash())){?這不適合我。 – Daniel
還有其他的問題,但我認爲如果你只是刪除'function unHash(){'和關閉'}',它們都會消失。除非你需要從某處調用'unHash'函數,否則這可能是你最好的方法。再加上那個調試語句。 –
我這樣做了,它仍然返回False。 – Daniel