Change post form

て烟熏妆下的殇ゞ 提交于 2019-12-11 06:49:54

问题


I have simple login form in my website. In given requirements stands, that password mustn't been sent to server, but only MD5 hash. I took simple MD5 function and now, when with onClick on submit button I change hidden text from password to md5(password). This works fine, but user sees, that something with his password is happening. I would like to make it transparent and change this particular part of form dynamically with onPost (or smth like this) callback.

I can't find any tutorials how to deal with manipulating POST table/form in javascript (jquery?) so if anyone could help I would appreciate.


回答1:


As far as I know input fields that don't have name don't get submitted to the server. So you could have a hidden field and in the onsubmit event of the form copy the value of the password field into the hidden field by applying the MD5 checksum:

<form method="post" action="/login">
    <input type="password" id="password" />
    <input type="hidden" name="password" id="hiddenpassword" />
    <input type="submit" value="Login" />
</form>

and then:

$('form').submit(function() {
    var password = $('#password').val();
    var md5 = MD5(password);
    $('#hiddenpassword').val(md5);
    return true;
});


来源:https://stackoverflow.com/questions/6321316/change-post-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!