我用crypt()函數加密了我的密碼。 當用戶想要登錄如何檢查存儲在數據庫中的密碼與此輸入?我如何檢查登錄頁面中的密碼?
防爆:
$pass = "fgyi34".$pass."@1187Gh";
$hashed_password = crypt($pass);
我用crypt()函數加密了我的密碼。 當用戶想要登錄如何檢查存儲在數據庫中的密碼與此輸入?我如何檢查登錄頁面中的密碼?
防爆:
$pass = "fgyi34".$pass."@1187Gh";
$hashed_password = crypt($pass);
對於新用戶。
crypt
密碼並將其存儲在數據庫中。
爲現有用戶
crypt
密碼並將其當用戶點擊提交按鈕,你的數據庫上較早的加密的密碼比較加密的密碼存儲在一個變量。如果密碼不匹配,則向用戶顯示密碼錯誤的消息。
在註冊時將$ hashed_password存儲到數據庫中。
在登錄檢查與存儲的一個的加密的密碼在MySQL查詢
隱窩密碼不能被顛倒,從而遵循密碼加密下面的步驟:
1)產生一個隨機數和加密。 2)加密後將其保存在數據庫列字段中。 3)在登錄時,交叉檢查輸入的密碼並再次加密。 4)用哈希密碼檢查這個新密碼。
請閱讀Manual
。
一個可選的鹽字符串,以散列爲基礎。如果沒有提供, 行爲由算法實現定義,並可能導致 意想不到的結果
例子#1
<?php
$hashed_password = crypt('mypassword'); // let the salt be automatically generated
/*
You should pass the entire results of crypt() as the salt for comparing a
password, to avoid problems when different hashing algorithms are used. (As
it says above, standard DES-based password hashing uses a 2-character salt,
but MD5-based hashing uses 12.)
*/
if (crypt($user_input, $hashed_password) == $hashed_password) {
echo "Password verified!";
}
?>
所以每當用戶嘗試登錄,獲得加密後password
從數據庫與他們的username
並將user input
和hashed password
與crypt
進行比較。
實施例#2
<?php
$username = $_POST["username"];
$password = $_POST["password"];
$passhash = "SELECT `password` FROM `table` WHERE `username` = '{$username}'";
// execute the query and get the hashed password
if ($passhash) {
if (crypt($password, $passhash) == $passhash) {
echo "Password verified!";
}
}
?>
事情是[此](http://stackoverflow.com/questions/8199244/using-crypt-and-verifying-not-sure-how-it-works )? – machineaddict
你需要在runnig sql查詢 – Garry
之前填入用戶在登錄表單中填寫的密碼,但我知道每次輸出不同的輸出 – Saeid