问题描述
我的html页面中有表格
I have form in my html page
<form id="login_form" method="POST" action="index.php">
<table>
<tr>
<td><label style="color:#47A3FF;" for="name" title="User name">
Username</label></td>
<td><input style="color:#47A3FF;" dojoType="dijit.form.TextBox"
type="text" name="username"></td>
</tr>
<tr>
<td><label style="color:#47A3FF;" for="loc">Password: </label></td>
<td><input style="color:#47A3FF;" dojoType="dijit.form.TextBox"
type="password" name="password"></td>
</tr>
<tr>
<td colspan="2" align="center">
<button dojoType="dijit.form.Button" class="soria" style="border: 1px solid black; float:right;"
type="submit">Login</button></td>
</tr>
</table>
</form>
通过网络发送用户名和密码时,我需要使用SHA256吗?如何对那些数据使用SHA256(我有sha256_hash函数,该函数使用字符串并返回哈希值,但我不知道在哪里调用该函数)?
Do I need to use SHA256 when I send username and password over network ? How to use SHA256 over those data ( I have function sha256_hash which use string and return hashed value, but I don't know where to call that function ) ?
推荐答案
提交表单时,您应该对所需的值进行哈希处理.
You should hash the desired values when the form is submitted.
我猜这样的东西应该可以工作:
I guess something like this should work :
HTML
<form onsubmit="return myOnSubmit(this);">
JavaScript
JavaScript
function myOnSubmit(aForm) {
//Getting the two input objects
var inputUsername = aForm['username'];
var inputPassword = aForm['password'];
//Hashing the values before submitting
inputUsername.value = sha256_hash(inputUsername.value);
inputPassword.value = sha256_hash(inputPassword.value);
//Submitting
return true;
}
由于存在在提交之前对值进行哈希处理"部分,因此如果您具有 maxlength
属性,则该方法将不起作用,因为哈希值比仅清除密码要长得多.
EDIT :Because of the 'Hashing the values before submitting' part, it will not work if you have a maxlength
property, because hashed values are much longer than just the clear password.
如果您必须使用最大长度,那么您将需要实现HIDDEN FIELDS并更改这些值,并确保未提交包含明文数据的字段(在< FORM>之外)
标签).
If you MUST use a maximum length, then you would need to implement HIDDEN FIELDS and changing those values, and making sure the fields containing the clear data aren't submitted (outside of the <FORM>
tag).
这篇关于对表单中的数据进行代码哈希处理的功能-已经具有功能,但是不知道在哪里调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!