同题,不复述
附上md5.js原文件下载地地址:
md5.js
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登录</title>
<script src="{% static '/md5.js'%}"></script>
<script type="text/JavaScript">
function gook() {
var S,X;
S = document.getElementById("username");
if (S.value == "")
{
alert("用户名不可为空");
S.focus();
return;
}
S = document.getElementById("userpw");
if (S.value == "")
{
alert("密码不可为空");
S.focus();
return;
}
else
{
var hash = md5(S);
document.getElementById("pwmd5").value = hash;
}
var f = document.getElementById("userlogin");
f.submit();
}
</script>
</head>
<body>
<table width="300" border="1">
<form action="/postmain/" method="post" id="userlogin" name="userlogin">
用户名:<input type="text" name="username" id="username"/>
密 码:<input type="password" name="userpw" id="userpw"/>
<input type="hidden" name="pwmd5" id="pwmd5"/>
<input type="hidden" name="logined" value="True" id="logined"/>
<td><a href="#" onclick="gook()">登录</a></td>
</form>
</table>
</body>
</html>
已解决:
不应该是
var hash = md5(S);
应该是
var hash = md5(S.value);
可能你用错了, 我不是这样用的, 你可以试一下我的用法; 得到密文后台, 可以把密文复制到一些md5的解析网站上解析看能不能得到你加密的内容
let hash = md5.create();
hash.update("123456"); // 加密123456
console.log(hash.hex()); // 用 hash.hex() 得到密文 ;