private void RegistPan_Click(object sender, EventArgs e) { String username = UsernameText.Text; String password = PasswordText.Text; String repassword = RePasswordText.Text; int Sex = 1; if (Man.Checked) { Sex = 1; } if (Woman.Checked) { Sex = 2; } String c = ClassText.Text; String question = UserQuestion.Text; String answer = Answer.Text; if (repassword != password) { DialogResult dr = MessageBoxEx.Show(this, "两次密码输入不一致"); RePasswordText.Focus(); } else if (username == null || "".Equals(username) || password == null || "".Equals(password)) { DialogResult dr = MessageBoxEx.Show(this, "用户名和密码不能为空"); UsernameText.Focus(); } else if (question == "请选择或输入密保问题") { DialogResult dr = MessageBoxEx.Show(this, "请选择或输入密保问题"); UserQuestion.Focus(); } else if (answer == null || "".Equals(answer)) { DialogResult dr = MessageBoxEx.Show(this, "密保答案不能为空"); Answer.Focus(); } else { user u = new user(); u.username = username; u.password = password; u.sex = Sex; u.Class = c; u.question = question; u.answer = answer; userdao ud = new userdao(); if (ud.addUser(u)) { DialogResult dr = MessageBoxEx.Show(this, "注册成功"); this.Close(); } else { DialogResult dr = MessageBoxEx.Show(this, "注册失败"); } } }
public ActionResult Login(LoginModel model) { if (ModelState.IsValid) { var dao = new userdao(); var result = dao.Login(model.UserName, Encryptor.MD5Hash(model.Password), true); if (result == 1) { var user = dao.getbyid(model.UserName); var userSession = new Userlogin(); userSession.Name = user.USERNAME; userSession.UserId = user.ID; userSession.Groupid = user.GROUPID; userSession.Phone = user.PHONE; userSession.Address = user.ADDRESS; var listCredentials = dao.getcredential(model.UserName); Session.Add(Commonconst.SESSION_CREDENTIALS, listCredentials); Session.Add(Commonconst.USER_SESSION, userSession); return(RedirectToAction("Index", "DonKh")); } else if (result == 0) { ModelState.AddModelError("", "Tài khoản không tồn tại."); } else if (result == -1) { ModelState.AddModelError("", "Tài khoản đang bị khoá."); } else if (result == -2) { ModelState.AddModelError("", "Mật khẩu không đúng."); } else if (result == -3) { ModelState.AddModelError("", "Tài khoản của bạn không có quyền đăng nhập."); } else { ModelState.AddModelError("", "đăng nhập không đúng."); } } return(View("index")); }
private void LoginPan_Click(object sender, EventArgs e) { String username = UsernameText.Text; String password = PasswordText.Text; if (Student.Checked) { userdao ud = new userdao(); if (ud.findUser(username, password)) { DialogResult dr = MessageBoxEx.Show(this, "学生登录成功"); UserChooseForm ucf = new UserChooseForm(); ucf.username = username; ucf.Location = this.Location; ucf.StartPosition = FormStartPosition.Manual; ucf.Show(); } else { DialogResult dr = MessageBoxEx.Show(this, "用户名密码错误,登录失败"); } } else { admindao ad = new admindao(); if (ad.findadmin(username, password)) { DialogResult dr = MessageBoxEx.Show(this, "管理员登录成功"); backspace bk = new backspace(); bk.Location = this.Location; bk.StartPosition = FormStartPosition.Manual; bk.Show(); } else { DialogResult dr = MessageBoxEx.Show(this, "用户名密码错误,登录失败"); } } }