private void btnUpdateUser_Click(object sender, EventArgs e) { try { if (MessageBox.Show("Bạn có chắc muốn thay đổi tài khoản này?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string idStr = dgvUser.CurrentRow.Cells["ID"].Value.ToString(); string userName = dgvUser.CurrentRow.Cells["UserName"].Value.ToString(); if (userName.ToLower().Equals("admin") && !txtUserName.Text.Trim().ToLower().Equals("admin")) { MessageBox.Show("Tài khoản admin không thể đổi tên tài khoản", "Thông báo"); } else { int roleId = int.Parse(cbPermission.SelectedValue.ToString()); int active = chkDeactive.Checked ? 1 : 0; if (string.IsNullOrWhiteSpace(idStr) || string.IsNullOrWhiteSpace(txtUserName.Text.Trim())) { MessageBox.Show("Tài khoản không tồn tại", "Thông báo"); } else if ((!string.IsNullOrWhiteSpace(txtPassword.Text.Trim()) || !string.IsNullOrWhiteSpace(txtConfirm.Text.Trim())) && !txtPassword.Text.Trim().Equals(txtConfirm.Text.Trim())) { MessageBox.Show("Xác nhận mật khẩu không đúng", "Thông báo"); } else if (!txtPassword.Text.Trim().Equals(txtConfirm.Text.Trim())) { //Show error when input confirm password not similar with password MessageBox.Show("Mật khẩu không đúng", "Thông báo"); } else { int id = !string.IsNullOrWhiteSpace(idStr) ? int.Parse(idStr) : 0; AuthSuport.Register(id, txtUserName.Text.Trim().ToLower(), txtPassword.Text.Trim(), roleId, active, 0); MessageBox.Show("Lưu thành công", "Thông báo"); BindDataUserList(); } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK); } }
private void btnNewUser_Click(object sender, EventArgs e) { try { string userName = txtUserName.Text.Trim().ToLower(); string password = txtPassword.Text.Trim(); string confirmPassword = txtConfirm.Text.Trim(); if (password.Equals("")) { lbMessage.Visible = true; lbMessage.Text = "Mật khẩu không được trống"; lbMessage.ForeColor = Color.Red; } else if (!password.Equals(confirmPassword)) { //Show error when input confirm password not similar with password lbMessage.Visible = true; lbMessage.Text = "Mật khẩu xác nhận không đúng"; lbMessage.ForeColor = Color.Red; } else { var checkUser = AuthSuport.CheckUserExisted(userName); if (checkUser.Equals("true")) { int roleId = int.Parse(cbPermission.SelectedValue.ToString()); int active = chkDeactive.Checked ? 1 : 0; AuthSuport.Register(-1, userName, password, roleId, active, 1); MessageBox.Show("Tạo tài khoản thành công", "Thông báo"); BindDataUserList(); } else { lbMessage.Visible = true; lbMessage.Text = checkUser; lbMessage.ForeColor = Color.Red; } } } catch (Exception ex) { lbMessage.Visible = true; lbMessage.Text = ex.Message; lbMessage.ForeColor = Color.Red; } }
private void btnLogin_Click(object sender, EventArgs e) { string userName = txtUserName.Text.Trim(); string password = txtPassword.Text.Trim(); var isLogin = AuthSuport.Login(userName, password); if (isLogin == "true") { //Login successfull this.Hide(); frmHome home = new frmHome(); home.Show(); } else { labError.Text = isLogin; labError.ForeColor = Color.Red; labError.Visible = true; } }
public override async Task <IHttpActionResult> PostEntity(tbUser se) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var existUser = _db.tbUsers.Where(tbUser => (tbUser.UserName == se.UserName)).FirstOrDefault(); var user = se as tbUser; if (!(user is tbUser) || existUser != null) { return(BadRequest()); } user.Password = AuthSuport.GetMD5(user.Password); _db.tbUsers.Add(user); await _db.SaveChangesAsync(); return(Ok(user)); }