springmvc+hibernate实现记住密码

来源:互联网 发布:英语翻译发音软件 编辑:程序博客网 时间:2024/06/01 20:23
springmvc+hibernate登录功能实现记住密码今天在学习的过程中,看见了“记住密码”这一功能。我首先在网上查到的是这种方法http://www.itnose.net/detail/6088218.html
但是如果使用这种方法的话就要更改我以前写的登录功能。所以说我转换的思路,如何使用前端技术来实现这一功能。下面我就贴代码:
<script type="text/javascript">        //初始化页面时验证是否记住了密码        $(document).ready(function () {        if ($.cookie("rmbUser") == "true") {            $("#ck_rmbUser").attr("checked", true);            $("#txt_username").val($.cookie("username"));            $("#txt_password").val($.cookie("password"));        }        });        //保存用户信息和判断密码和用户名是否为空        function saveUserInfo(from) {            if ( $("#ck_rmbUser").is(":checked") ) { //这里要使用is(":checked")判断是否勾选                var str_username = $("#txt_username").val();                var str_password = $("#txt_password").val();                $.cookie("rmbUser", "true", { expires: 7 }); //存储一个带7天期限的cookie                $.cookie("username", str_username, { expires: 7 });                $.cookie("password", str_password, { expires: 7 });            }            else {                $.cookie("rmbUser", "false", { expire: -1 });                $.cookie("username", "", { expires: -1 });                $.cookie("password", "", { expires: -1 });            }            //判断是否为空            if($("#txt_username").val()==null || $("#txt_username").val()==""){                $("#msg1").html("用户名不用为空!");$("#msg2").html("");                return false;            }if($("#txt_password").val()==null || $("#txt_password").val()==""){                $("#msg2").html("密码不用为空!");$("#msg1").html("");                return false;            }else{                $("#msg1").html("");                $("#msg2").html("");                return true;}        };    </script>html代码
<div style="margin-left: 20px;width: 40px;height: 35px;background-color: #d2d3d5;text-align: center;position: relative;margin-top: 10px" >                    <input type="text" name="username"  id="txt_username" value="" style="width: 210px;height: 35px;"/>                </div>                <div style="margin-left: 20px;width: 40px;height: 35px;background-color: #d2d3d5;text-align: center;position: relative;margin-top: 10px" >                    <input type="password" name="password" id="txt_password" value="" style="width: 210px;height: 35px;"/>                </div>                <div style="margin-left: 20px;padding-top: 10px">                    <input type="checkbox" id="ck_rmbUser"/>   记住密码                </div>                <div style="margin-left: 20px;padding-top: 10px">                    <input type="submit" value="登    录"  onclick="saveUserInfo(this.form)" id="dengLu" style="width: 210px"/>                </div></div>



                                             
0 0
原创粉丝点击