·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> 网站建设开发 >> ASP.NET网站开发 >> 记住密码

记住密码

作者:佚名      ASP.NET网站开发编辑:admin      更新时间:2022-07-23

记住密码

感谢网上的一位朋友

前台代码

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