javascript - Code hash function over data in form - already have function but don't know where to call - Stack Overflow

I have form in my html page<form id="login_form" method="POST" action="inde

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>

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 ) ?

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>

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 ) ?

Share Improve this question edited Apr 7, 2011 at 12:55 Shaz 15.9k4 gold badges43 silver badges60 bronze badges asked Apr 7, 2011 at 12:50 DamirDamir 56.4k98 gold badges251 silver badges368 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

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

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;
}

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.

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).

<button dojoType="dijit.form.Button"  class="soria" style="border: 1px solid black; float:right;" type="submit" onclick="username.value=sha256_hash(username.value);password.value=sha256_hash(password.value)">Login</button></td>

Generally when you send sensitive data, you have only to worry about password, so you can hash password and leave user as it.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745370156a4624761.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信