记住密码

感谢网上的一位朋友

前台代码

<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可以赋进去吗,望高手指点,谢谢

转载于:https://www.cnblogs.com/yuanjiehot/p/4443586.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值