我已经为我的一个网站实现了本文中给出的示例: http://www.wikihow.com/Create-a-Secure-Login-Script-in-PHP-and-MySQL
一切顺利,直到IE9用户开始报告他们无法登录该网站。用户已启用javascript但我仍然无法解决为什么会发生这种情况。相同的用户可以使用其他浏览器登录,因此也不是忘记密码的情况(我非常怀疑!)
formhash函数的写法与文章中出现的完全相同(非常讨厌从图像中复制它!)
function formhash(form, password) {
console.log("Hashing form");
// 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();
}
提交时未报告任何错误,因此IE9似乎不支持任何错误。那么这个散列函数出了什么问题呢?
答案 0 :(得分:2)
原来IE9不喜欢修改表单输入,因此你必须在将元素添加到DOM之前设置值
function formhash(form, password) {
console.log("Hashing form");
// Create a new element input, this will be our hashed password field.
var p = document.createElement("input");
p.name = "p";
p.type = "hidden"
p.value = hex_sha512(password.value);
// NOW, add the new element to our form.
form.appendChild(p);
// Make sure the plaintext password doesn't get sent.
password.value = "";
// Finally submit the form.
form.submit();
}
感谢遇到我确切问题的this poor soul