我正在使用本教程 http://www.wikihow.com/Create-a-Secure-Login-Script-in-PHP-and-MySQL 以保護對我的網頁的訪問,並且我想通過重置密碼功能對其進行修改。不幸的是我的重設密碼的插件商店的東西登錄表單/密碼重置
這使得帳戶不能登錄該代碼被執行用戶註冊和工程就像一個魅力
$random_salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));
// Create salted password
$password = hash('sha512', $password . $random_salt);
// Insert the new user into the database
if ($insert_stmt = $mysqli->prepare("INSERT INTO members (username, email, password, salt) VALUES (?, ?, ?, ?)")) {
$insert_stmt->bind_param('ssss', $username, $email, $password, $random_salt);
// Execute the prepared query.
if (! $insert_stmt->execute()) {
header('Location: ../error.php?err=Registration failure: INSERT');
}
}
header('Location: ./register_success.php');
登錄處理:
// hash the password with the unique salt.
$password = hash('sha512', $password . $salt);
if ($stmt->num_rows == 1) {
// If the user exists we check if the account is locked
// from too many login attempts
if (checkbrute($user_id, $mysqli) == true) {
// Account is locked
// Send an email to user saying their account is locked
return false;
} else {
// Check if the password in the database matches
// the password the user submitted.
if ($db_password == $password) {
也適用精細。 (不是我的工作:)) ,現在我的一部分 - 隨機字符串發生器隨後通過散列
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$charactersLength = strlen($characters);
$randomString = '';
for ($i = 0; $i < 8; $i++) {
$randomString .= $characters[rand(0, $charactersLength - 1)];
}
$random_salt = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));
// Create salted password
$password = hash('sha512', $randomString . $random_salt);
if ($insert_stmt = $mysqli->prepare("UPDATE members SET password = ?, salt=? WHERE username= ?")){
$insert_stmt->bind_param('sss', $password, $random_salt, $username);
$insert_stmt->execute();
$insert_stmt->close();
}
復位腳本成功修改數據庫用戶,存儲正確的鹽和正確的哈希密碼。 測試通過在屏幕上顯示隨機文本和鹽,比這裏 http://www.convertstring.com/cs/Hash/SHA512
任何意見如何跟蹤哈希處理或提示如何解決它,將不勝感激結合。
我有一個懷疑,可能有一些麻煩JS這在客戶端哈希密碼
function formhash(form, password) {
// Create a new element input, this will be our hashed password field.
var p = document.createElement("input");
// Add the new element to our form.
form.appendChild(p);
p.name = "p";
p.type = "hidden";
p.value = hex_sha512(password.value);
// Make sure the plaintext password doesn't get sent.
password.value = "";
// Finally submit the form.
form.submit();
}
非常感謝您
你真的應該使用PHP的[內置函數(http://jayblanchard.net/proper_password_hashing_with_PHP .html)來處理密碼安全性。如果您使用的PHP版本低於5.5,則可以使用'password_hash()'[兼容包](https://github.com/ircmaxell/password_compat)。 –
修復什麼?你沒有告訴我們問題是什麼。 –
...不幸的是我的重置密碼插件存儲的東西,使帳戶無法登錄.... – FrantisekNebojsa