private void login() { //string strGetAd = "Select * From quyennv Where manv = '" + txtUser.Text + "' and matkhau = '" + txtPass.Text + "'"; try { DBAccess d = new DBAccess(); //DataTable dtb = d.getDS(strGetAd); User_BLL user = new User_BLL(); DataTable dtb = user.checkLogin(txtUser.Text, txtPass.Text); if (dtb.Rows.Count > 0) { DataRow q = dtb.Rows[0]; mnv = q["manv"].ToString(); qnv = q["id"].ToString(); string sql = "Select hoten From nhanvien Where manv = '" + txtUser.Text + "'"; DataTable dt = d.getDS(sql); DataRow r = dt.Rows[0]; MessageBox.Show("Xin chào " + r["hoten"].ToString() + "!", "Xin chào", MessageBoxButtons.OK); this.Hide(); this.Dispose(false); fm = new frmMain(); fm.Show(); } else { MessageBox.Show("Mã nhân viên hoặc mật khẩu không chính xác!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch (Exception ex) { MessageBox.Show("Lỗi: " + ex.Message); } }
protected void btnLogin_Click(object sender, EventArgs e) { string username = txtUsername.Text; string password = txtPassword.Text; if (user_bll.checkLogin(username, md5(password))) { context.Session["LoggedIn"] = "true"; context.Session["Username"] = username; Response.Redirect("InputForm.aspx"); } else { txtPassword.Text = ""; lblAlart.Text = "Username or password are incorrect, try again"; } }
protected void btnSave_Click(object sender, ImageClickEventArgs e) { Entity.User user_ = new Entity.User(); string username = context.Session["Username"].ToString(); string oldpass = txtOldPass.Text; string newpass = txtNewPass.Text; string confirm = txtConfirm.Text; if (userBLL.checkLogin(username, md5(oldpass))) { if (userBLL.updatePassword(username, md5(newpass))) { ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Change password successfully ');", true); } } else { ScriptManager.RegisterStartupScript(this, GetType(), "error", "alert('Fail, Old password is incorrect');", true); } }
public void TestLoginWithUserOnePassTrue() { var test = userBll.checkLogin(user11.Manv, user11.Mk); Assert.AreEqual(1, test.Rows.Count); }