//修改密码,已测 public int changePsw(int userID, string password) { int result; userAccess ua = new userAccess(); result = ua.updatePsw(userID, password); return result; }
//验证账号密码,已测 //result[0]返回数字UserID(大于1整数):登 陆成功 -1:密码错误 -2:账号不存在 //result[1]登陆成功返回用户角色 public int[] login(string name ,string psw) { int[] result = { 0, 0 }; customerAccess ca = new customerAccess(); userAccess ua = new userAccess(); User u = ua.SelectUserByName(name); //System.Diagnostics.Debug.WriteLine("我是输入密码" + psw); //System.Diagnostics.Debug.WriteLine("我是密码"+u.password); //移除空字符; string password= u.password.Trim(); if (u == null) { result[0] = -2; return result; } if (!psw.Equals(password)) { result[0] = -1; return result; } result[0] = u.userID; result[1] = u.role; return result; }
protected void CreateUserButton_Click(object sender, EventArgs e) { userBLL ubll = new userBLL(); string username = UserName.Text.Trim(); string password = Password.Text.Trim(); string name = Name.Text; string phone = Phone.Text; string email = Email.Text; string address = Address.Text; bool isCustomer = customerRadio.Checked; if (isCustomer) { if (ubll.registerAsCustonmer(username, password, name, phone, email, address) == 1) { HttpCookie cookie = new HttpCookie("Preferences"); cookie["username"] = username; userAccess ua = new userAccess(); User u = ua.SelectUserByName(username); cookie["userid"] = u.userID.ToString(); cookie["role"] = u.role.ToString(); Session["userid"] = u.userID.ToString(); Session["role"] = u.role.ToString(); Session["username"] = username; Response.Cookies.Add(cookie); //cookie有效1个月 cookie.Expires = DateTime.Now.AddMonths(1); //重定向到主页 Response.Redirect("~/Default.aspx"); } else { Label1.Text = "注册失败,请尝试使用另一个用户名注册"; UpdatePanel1.Update(); } } else { if (ubll.registerAsSeller(username, password, name, phone, email, address) == 1) { HttpCookie cookie = new HttpCookie("Preferences"); cookie["username"] = username; userAccess ua = new userAccess(); User u = ua.SelectUserByName(username); cookie["userid"] = u.userID.ToString(); cookie["role"] = u.role.ToString(); Session["userid"] = u.userID.ToString(); Session["role"] = u.role.ToString(); Session["username"] = username; Response.Cookies.Add(cookie); //cookie有效1个月 cookie.Expires = DateTime.Now.AddMonths(1); Directory.CreateDirectory(Server.MapPath("~/File/" + u.userID.ToString())); //重定向到主页 Response.Redirect("~/Default.aspx"); } else { Label1.Text = "注册失败,请尝试使用另一个用户名注册"; UpdatePanel1.Update(); } } }