private bool bLoginSuccess() { clsUser sv_oUser = new clsUser(); VietBaIT.Encrypt sv_oEncrypt = new VietBaIT.Encrypt(picCom.Tag.ToString()); if (!globalVariables.gv_ConnectSuccess) { return false; } if (!sv_oUser.bIsExisted(txtUID.Text.Trim())) { Utility.ShowMsg("Không tồn tại người dùng có tên đăng nhập là " + txtUID.Text.Trim() + ". Đề nghị nhập lại", "Thông báo"); txtUID.Focus(); return false; } if (!sv_oUser.bLoginSuccess(txtUID.Text.Trim(), sv_oEncrypt.Mahoa(txtPWD.Text.Trim()))) { MessageBox.Show("Sai mật khẩu đăng nhập", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); txtPWD.Focus(); return false; } return true; }
private void cmdLogin_Click(object sender, EventArgs e) { string sv_sPWD = string.Empty; VietBaIT.Encrypt sv_oEncrypt = new VietBaIT.Encrypt("Rijndael"); clsUser sv_oUser = new clsUser(); try { sv_sPWD = sv_oEncrypt.Mahoa(txtOldPwd.Text.Trim()); if (!txtNewPwd.Text.Trim().Equals(txtConfirm.Text.Trim())) { MessageBox.Show("Mật khẩu xác nhận phải giống mật khẩu mới!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); txtConfirm.Focus(); return; } //Kiểm tra xem đã nhập mật khẩu cũ đúng hay chưa? if (globalVariables.IsAdminLogin) { if (!sv_oUser.bLoginSuccessAdmin(globalVariables.UserName, sv_sPWD)) { MessageBox.Show("Sai mật khẩu đăng nhập", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); txtOldPwd.Focus(); return; } } else { if (!sv_oUser.bLoginSuccess(globalVariables.UserName, sv_sPWD)) { MessageBox.Show("Sai mật khẩu đăng nhập", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); txtOldPwd.Focus(); return; } } //Kiểm tra xem mật khẩu cũ và mật khẩu mới có giống nhau không if (txtNewPwd.Text.Trim().Equals(txtOldPwd.Text.Trim())) { MessageBox.Show("Đã thay đổi mật khẩu thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); return; } if (globalVariables.IsAdminLogin) { if (sv_oUser.bChangePasswordForAdmin(globalVariables.UserName, sv_oEncrypt.Mahoa(txtNewPwd.Text.Trim()))) { MessageBox.Show("Đã thay đổi mật khẩu thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); return; } } else { if (sv_oUser.bChangePassword(globalVariables.UserName, sv_oEncrypt.Mahoa(txtNewPwd.Text.Trim()))) { MessageBox.Show("Đã thay đổi mật khẩu thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); return; } } } catch (Exception ex) { } }