标签:
1、登陆页代码
1)引入js
<script type="text/javascript" src="${base}/resources/admin/js/jquery.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/jquery.validate.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/rsa/jsbn.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/rsa/prng4.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/rsa/rng.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/rsa/rsa.js"></script>
<script type="text/javascript" src="${base}/resources/admin/js/rsa/base64.js"></script>
2) 编写js代码
<script type="text/javascript">
$(document).ready(function(){
// RSA加密
$(‘#myform‘).submit(function(){
var $password = $(‘#password‘);
var $enPassword = $(‘#enPassword‘);
var rsaKey = new RSAKey();
rsaKey.setPublic(b64tohex("${modulus}"), b64tohex("${exponent}"));
var enPassword = hex2b64(rsaKey.encrypt($password.val()));
$enPassword.val(enPassword);
});
// 弹出登陆错误信息
if("${failure}"!=""){
alert("${failure}");
}
// JQuery Validate插件登陆表单验证
$(‘#myform‘).validate({
rules:{
username:{required:true},
password:{required:true,minlength:5},
kaptcha:{required:true,
remote:{
type:"post",
url:"${base}/kaptchaAjaxCheck",
data:{ kaptcha:function(){ return $(‘#kaptcha‘).val();}}
}}
},
messages:{
username:{required:"请输入用户名"},
password:{required:"密码不能为空!",minlength:"密码最小长度为5"},
kaptcha:{required:"验证码不能为空!",remote:jQuery.format("错误的验证码")}}
});
// 验证码
$(‘#kaptchaImage‘).click(function () {
$(this).attr(‘src‘, ‘${base}/kaptcha.jpg?‘ + Math.floor(Math.random()*100) );
});
});
</script>
3)正文代码
<form action="${base}/admin" method="post" id="myform">
<input type="hidden" id="enPassword" name="enPassword"> // 隐藏域,enPassword,用来设置存放被上面的RSA加密之后的密文代码
username:<input type="text" id="username" name="username"><br>
password:<input type="text" id="password" name="password"><br>
kaptcha:<input type="text" id="kaptcha" name="kaptcha"/><br> // kaptcha验证码输入框
<img src="${base}/kaptcha.jpg" id="kaptchaImage"/><br> //kaptcha验证码显示图片
<input type="submit" value="submit">
</form>
项目记录:登陆( 保存用户名密码 kaptcha验证码 shiro权限管理 RSA加密 非明文保存)
标签:
原文地址:http://www.cnblogs.com/appzhang/p/4539866.html