你好,我正在學(xué)習(xí) XAMPP 并創(chuàng)建用戶數(shù)據(jù)庫。對于用戶的密碼和鹽,我很困惑。老師說鹽長度應(yīng)該與密碼長度相同。例如,如果我將密碼長度 max 設(shè)置為 20,那么 salt 也應(yīng)該為 20。但在我將密碼數(shù)據(jù)插入數(shù)據(jù)庫的測試下。無論salt長度如何變化,echo cryptoPassword($password . $salt),長度始終為40。如果我在數(shù)據(jù)庫中設(shè)置密碼長度小于40,則無法將encryptedPassword插入數(shù)據(jù)庫密碼中。我必須將數(shù)據(jù)庫密碼長度調(diào)整為40或更長,然后插入數(shù)據(jù)才能工作。那么是因為鹽長度總是保持40嗎?那么數(shù)據(jù)庫中的密碼長度必須大于/等于40?PHP code?$email = htmlentities($_REQUEST['email']);$firstName = htmlentities($_REQUEST['firstName']);$lastName = htmlentities($_REQUEST['lastName']);$password = htmlentities($_REQUEST['password']);$birthday = htmlentities($_REQUEST['birthday']);$gender = htmlentities($_REQUEST['gender']);$salt = openssl_random_pseudo_bytes(20);$encryptedPassword = sha1($password . $salt);
1 回答

POPMUISE
TA貢獻1765條經(jīng)驗 獲得超5個贊
根據(jù)問題所附的圖像,您正在嘗試將(假定的)用戶輸入的密碼存儲在數(shù)據(jù)庫中。這使得散列變得毫無意義,因為生成密碼散列的全部目的是在數(shù)據(jù)庫入侵的情況下保護密碼。
在您的情況下,如果您堅持使用該sha1()
函數(shù)生成哈希,我建議您password
從表中刪除該列,并添加一個存儲 40 個字符長度的字符串的新列來存儲您的哈希。
- 1 回答
- 0 關(guān)注
- 103 瀏覽
添加回答
舉報
0/150
提交
取消