[英]UserCake password hashing / sha1() function isnt working
我正在使用 UserCake 並遇到了問題。 由於某種原因, generateHash()
函數不再一致地工作。 這是我正在查看的內容:
funcs.php <-- 函數所在的位置
function generateHash($plainText, $salt = null) {
if ($salt === null) {
$salt = substr(md5(uniqid(rand(), true)), 0, 25);
} else {
$salt = substr($salt, 0, 25);
}
return $salt . sha1($salt . $plainText);
}
class.newuser.php <-- 調用函數創建密碼的地方
//Construct a secure hash for the plain text password
$secure_pass = generateHash($this->clean_password);
login.php <-- 調用函數來比較密碼的地方
//Hash the password and use the salt from the database to compare the password.
$entered_pass = generateHash($password,$userdetails["password"]);
if($entered_pass != $userdetails["password"]) {
$errors[] = lang("ACCOUNT_USER_OR_PASS_INVALID");
} else {
//Passwords match! we're good to go'
}
我可以成功創建一個新帳戶。 但是當我登錄時,login.php 創建的哈希密碼與新用戶類創建的密碼不同。 例如,當我登錄時,我將print_r
放在輸入的哈希密碼和數據庫中的哈希密碼上,這是返回的內容:
$entered_pass = 62b8ce100193434601929323a13a4d95bd3c6535b014e6444516af13f605f36f7
database pass = 62b8ce100193434601929323a153564aaeb4ad75d57b353ee8918cd9829cb5e1b
我唯一能想到的是散列密碼從第 26 個字符開始偏離,並且$salt
看起來有 25 個字符(假設這是最大長度?)。 所有這些都是庫存的 UserCake 東西,所以我不明白為什么它如此不一致。
我會注意到,如果我復制散列的$entered_pass
(那里的第一個)並將其粘貼到數據庫中,我將成功登錄。
編輯>>>
再看一遍后,我認為問題歸結為sha1($salt . $plainText);
. 看起來好像在第一個$salt
之后事情開始有所不同。 此外,當我刪除它完美登錄的sha1()
函數時,我只是想知道這是否對安全性有任何重大影響。
我有同樣的問題。 經過一些研究,我發現使用 password_hash() 函數是最新的。
我將class.newuser.php中的 $secure_pass var 更改為...
//Construct a secure hash for the plain text password
$secure_pass = password_hash("$this->clean_password", PASSWORD_DEFAULT);
類.user.php
//Update a users password
public function updatePassword($pass)
{
global $mysqli,$db_table_prefix;
$secure_pass = password_hash("$pass", PASSWORD_DEFAULT);
$this->hash_pw = $secure_pass;
$stmt = $mysqli->prepare("UPDATE ".$db_table_prefix."users
SET
password = ?
WHERE
id = ?");
$stmt->bind_param("si", $secure_pass, $this->user_id);
$stmt->execute();
$stmt->close();
}
登錄.php
// Use built in PHP password hashing
if (!password_verify($password, $userdetails["password"])) {
// Login Error Attempt Handler
login_attm_hand();
//Again, we know the password is at fault here, but lets not give away the combination incase of someone bruteforcing
$errors[] = lang("ACCOUNT_USER_OR_PASS_INVALID");
}
我認為這就是我必須在我的網站上更新的所有內容。 如果您有任何錯誤,請告訴我,我可以嘗試提供幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.