• 记住密码


    感谢网上的一位朋友

    前台代码

    <tr>
                            <td align="right">登录名:</td>
                            <td>
                                <input type="text" class="text_login" id="TB_uid" runat="server" maxlength="30"   />
                            </td>
                            </tr>
                        <tr>
                            <td align="right">密&nbsp;&nbsp;&nbsp;&nbsp;码:</td>
                            <td>
                                <asp:TextBox ID="TB_pwd" TextMode="Password" runat="server" class="text_login" maxlength="30"></asp:TextBox>
                                <%--<input type="password"  id="" runat="server"     />--%>
                            </td>
                           </tr>
                         <tr>
                      
                            <td colspan="2" height="2px" align="right">
                                <asp:CheckBox ID="RememberUser" runat="server"  Text="记住密码"/></td></tr>
    
                        <tr>
                      
                            <td colspan="2" align="left">
                                 <asp:Button ID="LoginBtn" runat="server" Text="登录" OnClick="LoginBtn_Click" /><asp:Button ID="CancleBtn" runat="server" Text="取消"  OnClick="CancleBtn_Click"/><asp:Button ID="ModifiBtn" runat="server" Text="修改密码" OnClick="ModifiBtn_Click"/>
                            
    View Code

    后台代码

     HttpCookie cookie = new HttpCookie("USER_COOKIE");
                    if (this.RememberUser.Checked)
                    {
                         //所有的验证信息检测之后,如果用户选择的记住密码,则将用户名和密码写入Cookie里面保存起来。
                        cookie.Values.Add("UserName", this.TB_uid.Value.Trim());
                        cookie.Values.Add("UserPassword", this.TB_pwd.Text.Trim());
                         //这里是设置Cookie的过期时间,这里设置一个星期的时间,过了一个星期之后状态保持自动清空。
                        cookie.Expires = DateTime.MaxValue; ;
                         HttpContext.Current.Response.Cookies.Add(cookie);
                    }
                     else
                    {
                       if (cookie!= null)
                        {
                            //如果用户没有选择记住密码,那么立即将Cookie里面的信息情况,并且设置状态保持立即过期。
                            Response.Cookies["USER_COOKIE"].Expires = System.DateTime.Now.AddDays(-1);
                        }
                     }
    View Code
            //读取保存的Cookie信息
                HttpCookie cookies = Request.Cookies["USER_COOKIE"];
                 if (cookies != null)
               {
    
                   if (DateTime.Now.CompareTo(cookies.Expires) > 0)
                   //if (Response.Cookies["SAZYGusername"].Expires != System.DateTime.Now.AddDays(-1))
                   {
                       //如果Cookie不为空,则将Cookie里面的用户名和密码读取出来赋值给前台的文本框。
                       this.TB_uid.Value = cookies["UserName"];
                       this.TB_pwd.Attributes.Add("Value", cookies["UserPassword"]);
                       //这里依然把记住密码的选项给选中。
                       try
                       {
                           this.RememberUser.Checked = true;
                       }
                       catch
                       {
    
                       }
                   }
                }
    View Code

    input密码框赋不了值,非要用textbox,不知道jquery可以赋进去吗,望高手指点,谢谢

  • 相关阅读:
    基本架构思想
    tensorflow|tf.train.slice_input_producer|tf.train.Coordinator|tf.train.start_queue_runners
    tfsenflow队列|tf.train.slice_input_producer|tf.train.Coordinator|tf.train.start_queue_runners
    tensorflow队列tf.FIFOQueue | enqueue | enqueue_many | dequeue | dequeue_many
    Tensorflow-gpu1.13.1 和 Tensorflow-gpu2.0.0共存之安装教程
    pandas相关操作
    Numpy的基本运算及操作
    Numpy基础之创建与属性
    Series序列
    os.walk|图片数据集
  • 原文地址:https://www.cnblogs.com/yuanjiehot/p/4443586.html
Copyright © 2020-2023  润新知