• Cookie记住密码


    Cookie 记住密码!


     

    <!DOCTYPEhtml>

    <htmllang="zh-CN">

    <head>

       <metacharset="UTF-8">

       <scripttype="text/javascript"src="${base}/js/jquery.cookie.js"></script>

       <scripttype="text/javascript"src="${base}/js/jquery.base64.js"></script>

       <scriptsrc="${base}/js/user_login.js"></script>

       <title>用户登录</title>

    </head>

    <body>

           <formid="user-login">

                       <divclass="row col m8offset-m2 valign-wrapper">

                           <spanclass="col m4">账号:</span>

                           <inputname="loginname"type="text"placeholder="请输入账号"id="loginname">

                        </div>

                       <divclass="row col m8offset-m2 valign-wrapper">

                           <spanclass="col m8offset-m3"id="wrong"></span>

                       </div>

                        <divclass="row col m8offset-m2 pswtop valign-wrapper">

                           <spanclass="col m4">密码:</span>

                           <inputname="password"type="password"placeholder="请输入密码"id="password">

                           <spanstyle="color:red"></span>

                        </div>

                        <divclass="row col m8offset-m2 valign-wrapper">

                           <inputtype="checkbox"class="filled-in"id="filled-in-box"/>

                           <labelfor="filled-in-box">记住密码</label>

                       </div>

                        <divclass="row col m8offset-m2">

                           <spanstyle="color:red"></span>

                           <aclass="btn col m4offset-m2"id="login">登录</a>

                           <buttontype="reset"class="btn col m4 offset-m1"id="reset">重置</button>

                        </div>

            </form>

    </body>




    1.       //首页在页面引入这两个js文件! 

             <scripttype="text/javascript"src="${base}/js/jquery.cookie.js"></script>

            <scripttype="text/javascript"src="${base}/js/jquery.base64.js"></script>

             Cookie.js是操作浏览器cookie的 base64是对cookie进行加密的!

    //获取cookie

            //记住用户名在浏览器没关闭情况下使用。直接给用户名赋cookie里面的值

           if($.cookie("email")&&$("#user-login").find("input[name=loginname]")){

            $("#loginname").val($.base64.decode($.cookie("email")));

            }

           //判断用户是否勾选记住密码!

           if($.cookie("rember")=="true")

    {

               if($.cookie("pass")&&$("#user-login").find("input[name=password]")){

                    $("#password").val($.base64.decode($.cookie("pass")));

                    $("#filled-in-box").prop("checked","checked");

                }

            }

    3   //保存cookie

    var remember=$("#filled-in-box").is(":checked");  //用户是否勾选


    if(remember){

            $.cookie("email",$.base64.encode(logname),{

                     expires:14, });

           //将用户的用户名保存至cookieemail。保存时间是14天!

            $.cookie("pass",$.base64.encode(logpsw),{

                    expires:14,});

          //将用户的密码保存至cookiepass。保存时间是14天!

            $.cookie("rember",remember,{

                    expires:14,});

         //将是否记住密码的状态保存至cookierember.内容是布尔值,是truefalse。保存时间是14天!

            }else{  $.cookie("email",$.base64.encode(logname));

                    $.cookie("rember",remember);

        //用户不记住密码的情况下,cookie本次有效!


    }

     

  • 相关阅读:
    解决Windows 10每次重启默认浏览器都被重置为IE的一个办法
    使用cookie登录百度网盘账号
    【C++ Primer | 14】重载运算
    Visual Studio Code 快捷键的使用
    【C++ Primer | 8】IO库
    Git push常见用法
    Git 基础
    Git连接GitHub仓库详解
    ceph关于rpm包构建的教程
    monitor综合
  • 原文地址:https://www.cnblogs.com/lonecry/p/5074667.html
Copyright © 2020-2023  润新知