PDA

View Full Version : Secured Forms with JavaScript


DIGITALgimpus
11-17-2002, 10:37 PM
Found this nify script:
http://pajhome.org.uk/crypt/md5/index.html


Used by Yahoo! so I guess it's somewhat effective... my question is:

How to implement it into a form so that it only crypts the password?


Currently my form is:

<FORM ACTION="http://authentication.accettura.com/login.php" METHOD=POST>
<FONT SIZE="-1" FACE="Arial, Helvetica, sans-serif"><INPUT TYPE=text NAME=username VALUE="" SIZE=20>
<FONT SIZE="-1" FACE="Arial, Helvetica, sans-serif"><INPUT TYPE=password NAME=password VALUE="" SIZE=20>
<INPUT TYPE=hidden NAME=rd VALUE="URL">
<INPUT TYPE=submit NAME=submit VALUE="Login">
</FORM>


I only want to crypt the password. All the rest should stay the same....


Anyone know how to do this with javascript, and keep it compatible with as many browsers as possible?

Looks like a really good way to increase security.

beetle
11-18-2002, 12:37 AM
Do you own the PHP script that processes the form? PHP has a built-in MD5 function (http://www.php.net/manual/en/function.md5.php) that I use for storing passwords in a DB.

If not, then something like this (using the JS from the page you linked to) should work.<script type="text/javascript">
function md5Pass(f) {
f.Password_Crypted.value = hex_md5(f.Password.value);
f.Password.disabled = true;
return true;
}
</script>

<form action="http://authentication.accettura.com/login.php" method="post" onsubmit="return md5Pass(this);">
<input type="password" name="Password" id="Password" />
<input type="hidden" name="Password_Crypted" id="Password_Crypted" />
</form>

DIGITALgimpus
11-18-2002, 12:39 AM
Thanks...

The reason why I wanted to use the javascript was so that the text entered is encrypted before transfer....


I the PHP backend is also MD5 based.