1. First to download the JS file to http://pajhome.org.uk/crypt/md5/.
2. In the page file, add:
<script type= "Text/javascript" src= "Md5.js" ></script>
3. Use function Hex_md5 () for encryption, for example:
Frm.pwd.value =hex_md5 (Frm.pwd.value);
Examples of Use:
HTML code
- <html>
- <head>
- <script type="Text/javascript" src="Md5.js"></script>
- <script>
- function MD5 () {
- var hash=hex_md5 (document.getElementById ("text"). value);
- document.getElementById ("result"). value=Hash;
- }
- function trans () {
- Frm.pwd.value =hex_md5 (frm.pwd.value);
- document.getElementById ("Result2"). value=Frm.pwd.value;
- }
- function Submit () {
- Default commit processing, custom commit pre-processing method do not use submit as function name
- }
- onsubmit="Pwd.value =hex_md5 (pwd.value)"
- </Script>
- </head>
- <body>
- http://pajhome.org.uk/crypt/md5/<br>
- MD5 encryption:<br>
- before conversion: <input type=" text " id=" text " style=" width:300 " value=" Hello world "/><br>
- Converted:<input type="text" id="result" style="width:300"/><BR >
- <input type="button" value="test" onclick="MD5 ()"/>
- <br>
- <form name="frm" >
- Name:<input type="text" id="name" /><br>
- Password:<input type="password" id="pwd"/><br>
- <input type="button" value="Submit" onclick="trans ()" /><BR >
- Encrypted password:<input type="text" id="result2" style="width:300"/>
- </form>
- </body>
- </html>
from:http://hongan.iteye.com/blog/287044
MD5 encryption for JavaScript