dottext学习笔记4 登陆页面

来源:互联网 发布:resnet caffe github 编辑:程序博客网 时间:2024/06/03 14:59

1 页面设计

<form id="frmLogin" method="post" runat="server">
<asp:textbox id="tbUserName" runat="server" CssClass="Textbox"></asp:textbox><br>
<asp:requiredfieldvalidator id="Required_User" runat="server" ErrorMessage="xx" ControlToValidate="tbUserName"/>
<table runat="server" id="tbAuthenCode">
<p style="MARGIN: 4px 0px 0px 70px">

给textbox增加onKeyPress属性
tbUserName.Attributes.Add("onKeyPress","checkEnter(event,this)");
tbPassword.Attributes.Add("onKeyPress","checkEnter(event,this)");
加载js代码到当前页面
this.RegisterClientScriptBlock("LoginScript",sr.ReadToEnd());
 
2 代码实现

密码认证
IsValidPassword,把文本密码hash散列,跟数据库中的密码字符串比较
密码散列:
password = password.ToLower();
   Byte[] clearBytes = new UnicodeEncoding().GetBytes(password);
   Byte[] hashedBytes = ((HashAlgorithm) CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
   return BitConverter.ToString(hashedBytes);
验证通过后设Ticket
FormsAuthentication.SetAuthCookie(username,persist);
获取当前用户名:HttpContext.Current.User.Identity.Name

注销:        
           HttpContext.Current.Response.Cookies.Clear();
            System.Web.Security.FormsAuthentication.SignOut();

 

原创粉丝点击