private async void btnChange_Click(object sender, EventArgs e) { if (IsValidControls()) { try { string oldPassword = txtCurrent.Text.Trim(); if (EncryptionData.ValidateEncryptedData(oldPassword, oUser.Password)) { //Change the current password oUser.Password = txtNew.Text.Trim(); if (await userdata.ChangePassword(oUser)) { Logger.WriteToFile(Logger.FullName, "Changed password"); MessageBox.Show("Password has been successfully changed", "Change Password", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { MessageBox.Show("Unable to change password", "Change password", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { MessageBox.Show("Invalid Password. Please Enter the right password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show($"Sorry an error occured. \n{ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public async Task <IActionResult> changePFromDefault(DefaultPass data) { int result = await userData.ChangePassword(data); if (result > 0) { return(Ok(result)); } return(BadRequest()); }
public IActionResult ChangePassword(ChangePasswordModel data) { ChangePasswordModel model = new ChangePasswordModel(); model.UserId = User.Identities.First().Claims.Where(c => c.Type == ClaimTypes.Sid) .Select(c => c.Value).SingleOrDefault(); bool passChanged = _userData.ChangePassword(data.UserId, data.NewPassword); return(View(model)); }
public IActionResult ChangePassword(ChangePasswordModel data) { ChangePasswordModel model = new ChangePasswordModel(); model.UserId = User.Identities.First().Claims.Where(c => c.Type == ClaimTypes.Sid) .Select(c => c.Value).SingleOrDefault(); bool passChanged = _userData.ChangePassword(data.UserId, data.NewPassword); if (passChanged) { ViewBag.Message = "Password changed successfully!"; return(View(model)); } else { ViewBag.Message = "Error in changing password!"; return(View(model)); } }
public async Task <ServiceResponse> ChangePassword(LoginRequest lData) { ServiceResponse sResponse = new ServiceResponse(); try { var users = await _userData.FindByUsernameAsync(lData.userName); if (users.Count > 0) { var hashPassword = BCrypt.Net.BCrypt.HashPassword(lData.password); var changePwd = _userData.ChangePassword(lData.userName, hashPassword); if (changePwd.msgRespone == true) { sResponse.Status = "true"; sResponse.Message = changePwd.msg; } else { sResponse.Status = "false"; sResponse.Message = changePwd.msg; } } else { sResponse.Status = "false"; sResponse.Message = "Username does not exist"; } return(sResponse); } catch (Exception e) { sResponse.Status = "false"; sResponse.Message = e.Message; } return(sResponse); }
private async void btnNext_Click(object sender, EventArgs e) { try { if (isConfirmUser) { //Do for confirm user if (isValidConfirmUser()) { lblWait.Visible = true; string username = confirmUser1.txtUserName.Text.Trim(); oUser = await user.SelectUser(username); if (oUser != null) { //Show the security question lblWait.Visible = false; //Set the question securityQuestion1.lblQuestion.Text = GetQuestion(oUser.Question); securityQuestion1.BringToFront(); isConfirmUser = false; isQuestion = true; return; } else { lblWait.Visible = false; MessageBox.Show("Invalid Username. You are not a registered user", "Invalid User", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } if (isQuestion) { //Do for question. if (isValidQuestion()) { lblWait.Visible = true; string userAnswer = securityQuestion1.txtAnswer.Text.Trim().ToLower(); if (EncryptionData.ValidateEncryptedData(userAnswer, oUser.Answer)) { //Move to the next step lblWait.Visible = false; isQuestion = false; isPassword = true; userPassword1.BringToFront(); btnNext.Text = "Change"; return; } else { lblWait.Visible = false; MessageBox.Show("Invalid Answer. Please provide a valid answer.", "Invalid Answer", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } if (isPassword) { //Change the user's password if (isValidPassword()) { string newPassword = userPassword1.txtPassword.Text.Trim(); oUser.Password = newPassword; if (await user.ChangePassword(oUser)) { Logger.WriteToFile(oUser.FullName, "successfully changed password"); MessageBox.Show("Password has been successfully changed", "Change Password", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { MessageBox.Show("Unable to change password", "Please try again", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } } catch (Exception ex) { MessageBox.Show($"Sorry an error occured. \n{ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }