-
Notifications
You must be signed in to change notification settings - Fork 2
/
Login.aspx.cs
69 lines (67 loc) · 2.49 KB
/
Login.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MeeboDb;
public partial class Login : System.Web.UI.Page
{
//protected System.Web.UI.HtmlControls.HtmlGenericControl error_label;
protected void Page_Load(object sender, EventArgs e)
{
UserDB userDb = new UserDB();
if (IsPostBack)
{
string uPwd = Request.Form["password"];
string uName = Request.Form["user"];
DataSet resultSet = userDb.SearchByName(uName, "result");
if (resultSet.Tables["result"].Rows.Count > 0)
{
//用户名正确 检验密码和身份
foreach (DataRow user in resultSet.Tables["result"].Rows)
{
if (user["UPassword"].ToString() == uPwd)
{
if (user["UAdmin"].ToString() == "0")
{
//普通用户登录
Session["role"] = "user";
Session["name"] = uName;
Session["id"] = new Guid(user["UID"].ToString());
Response.Redirect("~/user/UserInfo.aspx");
}
else
{
//管理员登录
Session["role"] = "admin";
Session["name"] = uName;
Session["id"] = new Guid(user["UID"].ToString());
Response.Redirect("~/user/PersonalPage.aspx");
}
}
else
{
//用户名存在,密码错误·
ScriptManager.RegisterStartupScript(this.error_label, typeof(string), "error", "document.getElementById('error_label').innerText = '密码错误';", true);
return;
}
}
}
else
{
//用户名密码错误
ScriptManager.RegisterStartupScript(this.error_label, typeof(string), "error", "document.getElementById('error_label').innerText = '用户不存在';", true);
return;
}
}
else
{
if (Session["name"] != null)
{
Session.Clear();
}
}
}
}