温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:多功能在线考试系统改进版源码
当前文件:
OnLineExamUpdate/Web/Login.aspx.cs,打开代码结构图
OnLineExamUpdate/Web/Login.aspx.cs,打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
using OnLineExam.BusinessLogicLayer; 12
13
public partial class Web_Login : System.Web.UI.Page 14
{ 15
protected void Page_Load(object sender, EventArgs e) 16
{ 17
if (!IsPostBack) 18
{ 19
if (!Object.Equals(Request.Cookies["UserID"], null)) 20
{ 21
HttpCookie readcookie = Request.Cookies["UserID"]; 22
this.txtUserID.Text = readcookie.Value; 23
} 24
} 25
26
} 27
//登录按钮事件 28
protected void imgBtnLogin_Click(object sender, ImageClickEventArgs e) 29
{ 30
Users user = new Users();//创建Users对象user 31
string pwdMd5 = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txtPwd.Text.Trim(), "MD5").ToString(); 32
if (String.Compare(Request.Cookies["yzmcode"].Value, Validator.Text, true) != 0) 33
{ 34
lblMessage.Text = "验证码错误!"; 35
} 36
else 37
{ 38
if (user.CheckPassword(txtUserID.Text.Trim()))//根据用户编号查询用户密码 39
{ 40
if (user.UserPwd == pwdMd5)//输入密码与用户密码相同 41
{ 42
if (object.Equals(Request.Cookies["UserID"], null)) 43
{ 44
CreateCookie(); 45
} 46
else 47
{ 48
CreateCookie(); 49
} 50
Session["userID"] = txtUserID.Text.Trim();//存储用户编号 51
Response.Redirect("Default.aspx");//转向管理员操作界面 52
} 53
else//密码错误,给出提示 54
{ 55
lblMessage.Text = "您输入的密码错误!"; 56
} 57
} 58
else//用户不存在,给出提示 59
{ 60
lblMessage.Text = "该用户不存在!"; 61
} 62
} 63
} 64
protected void ChangeCode_Click(object sender, EventArgs e) 65
{ 66
67
} 68
private void CreateCookie() 69
{ 70
HttpCookie cookie = new HttpCookie("UserID"); 71
if (this.cbxRemeberUser.Checked) 72
{ 73
cookie.Value = this.txtUserID.Text; 74
} 75
cookie.Expires = DateTime.MaxValue; 76
Response.AppendCookie(cookie); 77
} 78
79
} 80
81





}
}