public IActionResult UpdatePassword([FromBody] UpdatePassword updatePassword) { int?id = User.GetUserId(); if (id == null) { return(BadRequest()); } var user = _authHandler.FindById((int)id); if (user == null) { return(BadRequest()); } if (!SecurePasswordHasher.Verify(updatePassword.CurrentPassword, user.PasswordHash)) { ModelState.AddModelError("Fail", "Password is incorrect"); return(BadRequest(ModelState)); } user.PasswordHash = SecurePasswordHasher.Hash(updatePassword.Password); _authHandler.Update(user); return(Ok()); }
private void updatePassword_Click(object sender, EventArgs e) { flowLayoutPanel.Controls.Clear(); UpdatePassword updatePassword = new UpdatePassword(); flowLayoutPanel.Controls.Add(updatePassword); }
public async Task <HttpStatusCode> UpdatePassword(UpdatePassword updPassword) { return(await PostAsync( "update-password", updPassword, "/api/v1/account/update-password")); }
public object Post(UpdatePassword request) { var user = _dao.FindById(request.AccountId); if (user == null) { throw HttpError.NotFound("Account not found"); } if (!string.IsNullOrEmpty(user.FacebookId) || !string.IsNullOrEmpty(user.TwitterId)) { throw HttpError.Unauthorized("Facebook or Twitter account cannot update password"); } if (!new PasswordService().IsValid(request.CurrentPassword, request.AccountId.ToString(), user.Password)) { throw new HttpError(ErrorCode.UpdatePassword_NotSame.ToString()); } var udpateCommand = new UpdateAccountPassword { AccountId = user.Id, Password = request.NewPassword }; _commandBus.Send(udpateCommand); // logout RequestContext.Get <IHttpRequest>().RemoveSession(); return(new HttpResult(HttpStatusCode.OK)); }
public async void when_updating_twitter_account_password() { var sut = new AccountServiceClient(BaseUrl, SessionId, new DummyPackageInfo(), null, null); const string password = "******"; var accountId = Guid.NewGuid(); var twitterId = Guid.NewGuid(); var newAccount = new RegisterAccount { AccountId = Guid.NewGuid(), Phone = "5145551234", Country = new CountryISOCode("CA"), Email = GetTempEmail(), Name = "First Name Test", TwitterId = twitterId.ToString() }; await sut.RegisterAccount(newAccount); await new AuthServiceClient(BaseUrl, SessionId, new DummyPackageInfo(), null, null).AuthenticateTwitter(newAccount.TwitterId); var request = new UpdatePassword { AccountId = accountId, CurrentPassword = password, NewPassword = "******" }; Assert.Throws <WebServiceException>(async() => await sut.UpdatePassword(request)); }
public async Task <IActionResult> UpdatePassword(UpdatePassword model) { try { using (var client = new HttpClient()) { Transaction transaction = new Transaction(); client.BaseAddress = new Uri("http://localhost:10293/api/Account"); HttpResponseMessage response = await client.PostAsJsonAsync <UpdatePassword>("Account/UpdatePassword/", model); var result = response.Content.ReadAsStringAsync().Result; Response content = JsonConvert.DeserializeObject <Response>(result); if (response.IsSuccessStatusCode) { TempData["passwordsuccess"] = content.Message; return(RedirectToAction("Index")); } ViewData["passworderror"] = content.Message; return(View()); } } catch (Exception e) { ViewData["error"] = e.Message; return(View("~/Views/Shared/ExceptionError.cshtml")); } }
public void TestOldPasswordShouldNotBeValid() { var repositoryMock = new Mock <IUserRepository>(); repositoryMock.Setup(m => m.GetByEmail(It.IsAny <Email>())).Returns( User.Create( new UserUuid("abc123"), new Email("*****@*****.**"), new HashedPassword("MyOldPasswordHashed--"), new Name("Test"), new Surname("abc123"), new PhoneNumber(123456789), new PostalCode(12345), new CountryCode("es") ) ); var updatePassword = new UpdatePassword(repositoryMock.Object, new HashPasswordStub()); Assert.Throws <InvalidPasswordException>( delegate { updatePassword.Handle( new Email("*****@*****.**"), new Password("MyOldPasswordError"), new Password("MyNewPassword") ); } ); }
public ActionResult UpdatePassword(UpdatePassword updpass) { if (ModelState.IsValid) { Person person = db.People.Find(User.Identity.Name); if (Helper.EncodePasswordMd5(updpass.oldpassWord) == person.password) { if (Helper.EncodePasswordMd5(updpass.NewpassWord) == Helper.EncodePasswordMd5(updpass.ConfirmpassWord)) { person.password = Helper.EncodePasswordMd5(updpass.ConfirmpassWord); db.Entry(person).State = EntityState.Modified; db.SaveChanges(); ViewBag.PasswordUpdateSuccess = true; } else { ModelState.AddModelError(string.Empty, "New password not matching with confirm password..!"); return(View()); } } else { ModelState.AddModelError(string.Empty, "Invalid old password..!"); return(View()); } } return(View()); }
public async Task <bool> UpdatePassword(UpdatePassword updatePassword, string token) { Uri uri = new Uri(Constant.URL_UPDATE_PASSWORD); try { string json = JsonSerializer.Serialize <UpdatePassword>(updatePassword); StringContent content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = null; client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); var method = new HttpMethod("PATCH"); var request = new HttpRequestMessage(method, uri) { Content = new StringContent( JsonConvert.SerializeObject(updatePassword), Encoding.UTF8, "application/json") }; response = await client.SendAsync(request); string contentResponse = await response.Content.ReadAsStringAsync(); GetLoginData code = JsonConvert.DeserializeObject <GetLoginData>(contentResponse); return(code.is_success); } catch (Exception ex) { return(false); } }
private void button11_Click(object sender, EventArgs e) { UpdatePassword UP = new UpdatePassword(); UP.GetUserID(TxtUserID.Text); UP.ShowDialog(); }
public void ValidatePropertiesTest() { LoginAdmin admin = new LoginAdmin { Username = "******", Password = "******" }; RegisterAdmin admins = new RegisterAdmin { Username = "******", Password = "******" }; UpdatePassword upt = new UpdatePassword { Username = "******", NewPassword = "******", RepeatPassword = "******" }; admins.ValidateAllProperties(); admin.ValidateAllProperties(); upt.ValidateAllProperties(); }
public Task <string> UpdatePassword(UpdatePassword updatePassword) { var req = string.Format("/accounts/{0}/updatepassword", updatePassword.AccountId); var response = Client.PostAsync <string>(req, updatePassword, logger: Logger); return(response); }
public async Task <IActionResult> UpdatePassword([FromBody] UpdatePassword model) { var result = new UpdatePasswordResult { Success = false }; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = await _userManager.FindByEmailAsync(model.Email); if (!await _userManager.HasPasswordAsync(user)) { result.Success = (await _userManager.AddPasswordAsync(user, model.NewPassword)).Succeeded; } else { if (!string.Equals(model.Password, model.ConfirmPassword)) { return(Ok(result)); } if (await _userManager.CheckPasswordAsync(user, model.Password)) { result.Success = (await _userManager.ChangePasswordAsync(user, model.Password, model.NewPassword)).Succeeded; return(Ok(result)); } } return(Ok(result)); }
private void buttonUpdate_Click(object sender, RoutedEventArgs e) { this.Visibility = Visibility.Hidden; UpdatePassword updatepassword = new UpdatePassword(labelName.Content.ToString()); updatepassword.Show(); }
public async Task <IActionResult> ProfileSettings(UpdatePassword model) { if (_HttpContextAccessor.HttpContext.User.Identity.IsAuthenticated) { if (ModelState.IsValid) { string UserID = _UserManager.GetUserId(_HttpContextAccessor.HttpContext.User); var User = await _UserManager.FindByIdAsync(UserID); var result = await _UserManager.ChangePasswordAsync(User, model.OldPassword.Trim(), model.NewPassword.Trim()); if (result.Succeeded) { TempData["Error"] = "Details Updated Successfully."; return(RedirectToAction("ProfileSettings")); } else { AddErrors(result); return(View(model)); } } else { return(View(model)); } } else { return(View("LoginPanel")); } }
public async Task <IHttpActionResult> updatepassword(UpdatePassword loanDetails) { // To do - Move the following code to a single method & use it across the project IEnumerable <string> tokenValues; string tokenValue = ""; if (Request.Headers.TryGetValues("AuthorizationToken", out tokenValues)) { tokenValue = tokenValues.FirstOrDefault(); } var Decryptdata = Decrypt(tokenValue); dynamic objPassword = JsonConvert.DeserializeObject(Decryptdata); string objPasswordUpd = objPassword.Password; var payment = await userService.UpdatePasswordAsync(tokenValue, loanDetails, objPasswordUpd); if (payment == null) { return(NotFound()); } return(Ok(payment)); }
public async Task <IActionResult> UpdatePassword(UpdatePassword model) { if (ModelState.IsValid) { var user = await userManager.FindByIdAsync(model.Id); if (user != null) { //var token = await userManager.GeneratePasswordResetTokenAsync(user); var result = await userManager.ResetPasswordAsync(user, model.Token, model.Password); if (result.Succeeded) { return(RedirectToAction("Users", "Administration")); } foreach (var error in result.Errors) { ModelState.AddModelError("", error.Description); } return(View(model)); } return(RedirectToAction("Users", "Administration")); } return(View(model)); }
public ActionResult UpdatePassword(UpdatePassword model) { if (ModelState.IsValid) { var user = UserManager.ChangePassword(User.Identity.GetUserId(), model.OldPassword, model.NewPassword); return(View("Update")); } return(View(model)); }
public async void UpdatepasswordSuccess(string result) { UpdatePassword = new UpdatePassword(); Cnfpassword = ""; await App.Current.MainPage.DisplayAlert("HMS", result, "OK"); OnPropertyChanged("UpdatePassword"); OnPropertyChanged("Cnfpassword"); }
public PasswordSettingsPageViewModel(IAccountService accountService) { _accountService = accountService; PasswordForm = new UpdatePassword(); InitializeCommands(); PasswordForm.CanExecutedChanged = SaveCommand.RaiseCanExecuteChanged; }
public async Task <IActionResult> UpdatePassword(UpdatePassword details) { bool isSuccessful = await _manager.UpdatePassword(details.Username, details.OldPassword, details.NewPassword); if (!isSuccessful) { return(BadRequest(new ErrorResponse(400, $"Username and/or password is incorrect."))); } return(NoContent()); }
public void TwoPasswordMatchTest() { UpdatePassword upt = new UpdatePassword { Username = "******", NewPassword = "******", RepeatPassword = "******" }; Assert.IsTrue(upt.CheckTwoPasswordMatch()); }
public async Task <IActionResult> UpdatePasswordAsync(int id, [FromBody] UpdatePassword command) { if (id != AccountID) { return(Forbid()); } await _adminService.UpdatePasswordAsync(id, command); return(NoContent()); }
public IHttpActionResult UpdatePassword(UpdatePassword details) { try { MySqlCommand cmd = new MySqlCommand(); sqlConn.Open(); cmd.Connection = sqlConn; cmd.CommandText = "spo_Update_Password"; cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@new_pass", details.Password); cmd.Parameters["@new_pass"].Direction = ParameterDirection.Input; cmd.Parameters.AddWithValue("@mob", details.Mobile); cmd.Parameters["@mob"].Direction = ParameterDirection.Input; int rows = cmd.ExecuteNonQuery(); if (rows > 0) { return Ok(new WebResponse { code = (int)HttpStatusCode.OK, status = "Ok", message = "Success", data = "Password is updated Successfully", error = false }); } return Ok(new WebResponse { code = (int)HttpStatusCode.BadRequest, status = "Not_Ok", message = "Success", data = "User not Exist", error = true }); } catch (Exception ex) { return Ok(new WebResponse { code = (int)HttpStatusCode.InternalServerError, status = "Not_Ok", message = "Error", data = ex.Message, error = true }); } }
private void gerUserInfo(int userID) { SqlConnection sqlCnn; SqlCommand sqlCmd; string sql = null; //connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"; sql = "[dbo].[LIST_UserProfile] '" + userID.ToString() + "'"; sqlCnn = new SqlConnection(conStr); try { sqlCnn.Open(); sqlCmd = new SqlCommand(sql, sqlCnn); SqlDataReader sqlReader = sqlCmd.ExecuteReader(); while (sqlReader.Read()) { lblName.Text = sqlReader["NAME"].ToString(); lblPosition.Text = sqlReader["Designation"].ToString(); lblEmailAddress.Text = sqlReader["EmailAddress"].ToString(); lblDepartment.Text = sqlReader["DepartmentName"].ToString(); if (sqlReader["DateModified"].ToString() == "") { UpdatePassword UP = new UpdatePassword(); UP.GetUserID(TxtUserID.Text); UP.ShowDialog(); } } sqlReader.Close(); sqlCmd.Dispose(); sqlCnn.Close(); //FormMode("EDIT"); //txtret.Text = "1"; // tabControl1.SelectedIndex = 0; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } //SqlDataReader rdr = cmd.ExecuteReader(); //while (rdr.Read()) //{ // string column = rdr["ColumnName"].ToString(); // int columnValue = Convert.ToInt32(rdr["ColumnName"]); //} }
public ActionResult UpdatePassword(UpdatePassword up) { if (ModelState.IsValid) { User u = uRepo.GetById((int)Session["UserId"]); if (u.Password == up.CurrentPassword && up.Password == up.ConPassword) { uRepo.PasswordUpdate(u.id, up.Password); return(RedirectToAction("ProfileDetails")); } } return(View("UpdatePassword", up)); }
public ActionResult Changepassword(UpdatePassword model) { var id = ((ClaimsIdentity)User.Identity).FindFirstValue(ClaimTypes.NameIdentifier); var user = db.Users.FirstOrDefault(u => u.Id.ToString() == id); if (user != null && user.Password == model.OldPassword) { user.Password = model.NewPassword; db.SaveChanges(); } return(RedirectToAction("Index", "Demands")); }
private async void UpdatePassword() { if (string.IsNullOrWhiteSpace(old_password.Text) || string.IsNullOrEmpty(old_password.Text) || string.IsNullOrWhiteSpace(new_password.Text) || string.IsNullOrEmpty(new_password.Text)) { await DisplayAlert("Erreur", "Les deux champs sont obligatiore", "OK"); } else { Barrel.ApplicationId = Constant.KEY_LOGIN; Login login = App.PizzaManager.GetLoginInProperties(); if (login != null) { UpdatePassword updatePassword = new UpdatePassword(old_password.Text, new_password.Text); string token = await App.PizzaManager.GetAuthentificationToken(login); waitLayout.IsVisible = true; if (string.IsNullOrEmpty(token)) { await DisplayAlert("Alert", "Veuillez vous connecter à votre", "OK"); await Navigation.PopAsync(); } bool b = await App.PizzaManager.UpdatePassword(updatePassword, token); if (b) { new_password.Text = ""; old_password.Text = ""; waitLayout.IsVisible = false; await DisplayAlert("Operation effectuée", "Votre mot de passe est bien modifier", "OK"); await Navigation.PopAsync(); } else { await DisplayAlert("Erreur", "Veuillez réessayer / attention à la longueur" + " du nouveau mot de passe", "OK"); waitLayout.IsVisible = false; new_password.Text = ""; old_password.Text = ""; } } else { await DisplayAlert("Erreur", "Veuillez vous connecter à votre compte", "OK"); } } }
public async Task UpdatePasswordReturnsMultipleErrorsIfMultipleDetailsAreMissing() { var controller = new AccountController(TestHelpers.CreateUserManager(), new NullLogger <AccountController>()); var model = new UpdatePassword { CurrentPassword = string.Empty, NewPassword = string.Empty }; var res = await controller.UpdatePassword(model); res.Should().BeIsBlankResultForPath(new[] { "currentPassword", "newPassword" }); }
public async Task <List<UpdatePassword>> GetById(string Email) { UpdatePassword objectCityTable = await _context.UserDetails.FindAsync(Email); List<UpdatePassword> item = new List<UpdatePassword>(); try { item.Add(objectCityTable); } catch(Exception ex) { throw new Exception(ex.Message); } return item; }