public async Task <ActionResult <PasswordResponse> > ResetPassword(ResetPasswordRequest model) { var user = await _userManager.FindByNameAsync(model.UserName); if (user == null) { return(NotFound()); } var password = _passwordGenerator.GeneratePassword(); var result = await ChangePassword(user, password); if (!result.Succeeded) { foreach (var error in result.Errors) { ModelState.AddModelError(error.Code, error.Description); } return(BadRequest(ModelState)); } var response = new PasswordResponse { Id = user.Id, UserName = user.UserName, Password = password }; return(response); }
public PasswordResponse Get() { //v1 /* * return new PasswordResponse * { * Password = Guid.NewGuid().ToString().Substring(0,6), * ApiVersion = "1.0", * ApiServer = Environment.MachineName * }; */ //v3 & 4 var response = new PasswordResponse { Password = GenerateRandomPassword(), ApiVersion = "4.0", ApiServer = Environment.MachineName }; _index.Add(new PasswordDetails(response)); return(response); }
public PasswordResponse getStudentPasswordData(String StudentID) { PasswordResponse response = new PasswordResponse(); try { using (SqlConnection con = new SqlConnection(ConString)) using (SqlCommand com = new SqlCommand()) { com.Connection = con; com.CommandText = "Select StudentPassword,Salt from Student where IndexNumber=@index"; com.Parameters.AddWithValue("@index", StudentID); con.Open(); SqlDataReader reader = com.ExecuteReader(); if (reader.Read()) { response.Password = reader["StudentPassword"].ToString().Trim(); response.Salt = reader["Salt"].ToString().Trim(); reader.Close(); return(response); } reader.Close(); return(null); } } catch (Exception ex) { return(null); } }
private async Task <PasswordResponse> UpdatePassword(AppUser appUser, string password, bool isAutoPassword, bool requirePasswordChange) { KeyValuePair <string, string> passwordResult; var response = new PasswordResponse(); if (appUser != null) { passwordResult = RandomGenerator.EncryptPassword(password, isAutoPassword); appUser.Password = passwordResult.Value; await _securityManagerRepository.UpdateUser(appUser); await _securityManagerRepository.SaveUser(); //Response response.Success = true; response.Email = appUser.UserName; response.Password = passwordResult.Key; } else { response.Message = "No se pudo resetear/cambiar el Password"; } return(response); }
public PasswordDetails(PasswordResponse response) { ApiVersion = response.ApiVersion; ApiServer = response.ApiServer; Length = response.Password.Length; HasUpper = response.Password.IndexOfAny(Upper) > -1; HasLower = response.Password.IndexOfAny(Lower) > -1; HasNumber = response.Password.IndexOfAny(Number) > -1; HasSpecial = response.Password.IndexOfAny(Special) > -1; }
public void ShouldRequestPasswordResetAsync() { // Arrange IUserApi userApi = CreateUserApi("reset"); // Act PasswordResponse response = userApi.RequestPasswordResetAsync("*****@*****.**").Result; // Assert response.security_question.ShouldBe("to be or not to be?"); }
private void OnPasswordGenerated(string password, PasswordResponse response) { if (response == PasswordResponse.Success) { PasswordTextBox.Text = password; FormsContainer.MainForm.HideTip(); } else { FormsContainer.MainForm.ShowTip("Select at least one of the options"); } }
public void ShouldRequestPasswordResetAsync() { // Arrange IUserApi userApi = CreateUserApi("reset"); // Act PasswordResponse response = userApi.RequestPasswordResetAsync("*****@*****.**").Result; // Assert response.SecurityQuestion.ShouldBe("to be or not to be?"); Should.Throw <ArgumentNullException>(() => userApi.RequestPasswordResetAsync(null)); }
private static bool handlePassword(ClientSession session) { PasswordRequest request = (PasswordRequest)session.Reader.GetMessage(); if (request.updatePassword) { db.setPassword(request.application, session.loginUsername.name); } var encryptedPw = db.getPassword(request.application.Name, request.application.Usernames[0].name, session.loginUsername.name); request.application.Usernames[0].password = encryptedPw; PasswordResponse resp = new PasswordResponse(request.application); byte[] payLoad = MessageUtils.SerializeMessage(resp).GetAwaiter().GetResult(); session.Client.Client.Send(payLoad); return(true); }
public async Task <IActionResult> PostResetPasswordAsync(string username, string password, string otp) { var response = new PasswordResponse(); try { var lawyer = await lawyerDataProvider.GetLawyer(username); if (lawyer == null) { response.Error = true; response.Message = "Could not find a Lawyer with Username: "******"Invalid reset token for user: "******"Password reset successfully."; return(Ok(response)); } } } catch (Exception e) { response.Error = true; response.Message = e.Message; response.StackTrace = e.StackTrace; return(BadRequest(response)); } }
public async Task <bool> CompletePasswordResetAsync(string email, string newPassword, string code, string answer) { if (email == null) { throw new ArgumentNullException("email"); } if (newPassword == null) { throw new ArgumentNullException("newPassword"); } if (code != null && answer != null) { throw new ArgumentException("You must specify either code or answer parameters but not both.", "answer"); } SqlQuery query = new SqlQuery { Fields = null }; query.CustomParameters.Add("login", true); PasswordResponse response = await base.RequestWithPayloadAsync <PasswordRequest, PasswordResponse>( method : HttpMethod.Post, resource : "password", query : query, payload : new PasswordRequest { Email = email, NewPassword = newPassword, Code = code, SecurityAnswer = answer } ); if (response.Success ?? false) { Session session = await GetSessionAsync(); base.BaseHeaders.AddOrUpdate(HttpHeaders.DreamFactorySessionTokenHeader, session.SessionId); } return(response.Success ?? false); }
public async Task <bool> ChangePasswordAsync(string oldPassword, string newPassword) { if (oldPassword == null) { throw new ArgumentNullException("oldPassword"); } if (newPassword == null) { throw new ArgumentNullException("newPassword"); } PasswordResponse response = await base.RequestWithPayloadAsync <PasswordRequest, PasswordResponse>( method : HttpMethod.Post, resource : "password", query : null, payload : new PasswordRequest { OldPassword = oldPassword, NewPassword = newPassword } ); return(response.Success ?? false); }
public PasswordResponse ValidationPassaword(string password) { try { Log.Information("Calling proccess to validate password."); var isValid = password.PatternPassword(); Log.Information("Create response data to request."); var response = new PasswordResponse { IsValid = isValid }; return(response); } catch (Exception ex) { Log.Error($"An error in proccess validating password. Error is: {ex}"); return(new PasswordResponse { IsValid = false }); } }
public PasswordResponsePacket(PasswordResponse response) { Response = response; }