public async Task <IActionResult> ChangePassword(ChangePasswordViewModel changePasswordViewModel) { try { var User = _userService.GetUserByUserName(changePasswordViewModel.Email); if (User == null) { return(BadRequest(changePasswordViewModel.Email + "is not registered. Or it is not confirmed")); } else { var is_password_true = _passwordService.Check(User.PasswordHash, changePasswordViewModel.Password); if (is_password_true) { User.PasswordHash = _passwordService.Hash(changePasswordViewModel.NewPassword); await _userService.UpdateUser(User); return(Ok("user password is updated successfully")); } else { return(BadRequest("Old password is in correct")); } } } catch (Exception ex) { throw ex; } }
private async Task <(bool, Seguridad)> IsValidUser(Login login) { Seguridad user = await _seguridadService.GetLoginByCredentials(login).ConfigureAwait(false); bool habilitado = user.Activo == Estado.Habilitado; bool isValid = false; if (habilitado) { isValid = _passwordService.Check(user.Password, login.Password); } return(isValid, user); }
private async Task <(bool, Security)> IsValidUser(UserLogin login) { var user = await _securityService.GetLoginByCredentials(login); var isValid = _passwordService.Check(user.Password, login.Password); return(isValid, user); }
private async Task <(bool isValid, Authentication authentication)> IsValidUser(UserLogin login) { var authentication = await _authenticationService.Login(login); var isValid = authentication is not null && _passwordService.Check(authentication.Password, login.Password); return(isValid, authentication); }
//private async Task<Tuple<bool, Security>> IsValidUser(UserLogin login) // Better return the tuple with thw following syntax private async Task <(bool, Security)> IsValidUser(UserLogin login) { //return true; // (18) Modify the method to actually validate a user var user = await _securityService.GetLoginByCredentials(login); var isValid = _passwordService.Check(user.Password, login.Password); return(isValid, user); }
private async Task <(bool, User)> IsValidUser(UserLogin login) { var user = await _userService.GetLoginByCredentials(login); if (user == null) { return(false, null); } var isValid = _passwordService.Check(user.hashPassword, login.Password); return(isValid, user); }
private async Task <(bool, User)> IsValidUser(UserLogin login) { User user = await _userService.GetLoginByCredentials(login); if (user == null) { throw new ArgumentException(); } var isValid = _passwordService.Check(user.Password, user.Salt, login.Password); return(isValid, user); }
private async Task <(bool, User)> IsValidUser(UserLoginReqDto login) { var user = await userService.GetByUsername(login); if (user == null) { return(false, user); } bool isValid = passwordService.Check(user.Password, login.Password); return(isValid, user); }
/// <summary> /// Validates the user. /// </summary> /// <param name="user">The user.</param> /// <returns>Task<Domain.Entities.User>.</returns> /// <exception cref="ArgumentNullException">The username: {user.UserName} or password: {user.Password} is incorrect</exception> public async Task <Domain.Entities.User> ValidateUser(UserDto user) { var exitsUser = await _userRepository.ValidateUser(user.UserName); if (exitsUser == null) { throw new ArgumentNullException($" The username: {user.UserName} or password: {user.Password} is incorrect "); } var valid = _passwordService.Check(exitsUser.Password, user.Password); return(valid ? exitsUser : null); }
private async Task <(bool, User)> IsValidUser(UserLogin login) { var hash = _passwordService.Hash(login.Password + login.User); var user = await _securityService.GetLoginByCredentials(login); if (user == null) { throw new BusinessException("User not valid"); } var isValid = _passwordService.Check(user.Password, login.Password + login.User); if (!isValid) { throw new BusinessException("Password not valid"); } return(isValid, user); }
public async Task <IActionResult> Post(UserLogin login) { try { var user = await _securityService.GetLoginByCredentials(login); if (user == null) { return(NotFound(new { message = $"No existe el usuario con el correo {login.Email}!" })); } var validation = _passwordService.Check(user.Password, login.Contraseña); //if it is a valid user if (validation) { var token = new Token(); token.JWTToken = GenerateToken(user); token.Usuario = _mapper.Map <UsuarioDto>(user); return(Ok(token)); } else { return(Unauthorized(new { message = "La contraseña proporcionada es incorrecta" })); } } catch (Exception err) { if (err.InnerException != null) { return(BadRequest(new { message = new { message = $"Error: {err.Message}\n Inner Error: {err.InnerException.Message}" } })); } else { return(BadRequest(new { message = $"Error: {err.Message} " })); } } }
private async Task <(bool, NetCoreUser)> GetUser(NetCoreUserRequest request) { try { var entity = _mapper.Map <NetCoreUser>(request); var response = await _userService.GetByUser(entity); if (!response.Item1) { return(false, null); } var isValid = _passwordService.Check(response.Item2.Password, request.Password); return(isValid, response.Item2); } catch (Exception ex) { _logger.LogError($"Ha ocurrido un error al crear una transacción. Error: {ex.Message}"); throw new Exception(ex.Message); } }
public async Task <IActionResult> ChangePassword(int id, UserChangePassword password) { try { var result = await _Repository.FindAsync(t => t.Id == id); if (result == null) { return(NotFound(new { message = $"{typeof(Usuario).Name} con el Id: {id} no existe " })); } if (!_passwordService.Check(result.Password, password.OldPassword)) { return(Unauthorized(new { message = "Contraseña incorrecta!" })); } string PHashNew = _passwordService.Hash(password.NewPassword); result.Password = PHashNew; _Repository.Update(result); return(Ok(new { message = "Contraseña Actualizada!" })); } catch (System.Exception err) { if (err.InnerException != null) { return(BadRequest(new { message = $"Error: {err.Message}\n Inner Error: {err.InnerException.Message}" })); } else { return(BadRequest(new { message = $"Error: {err.Message} " })); } } }
public bool Authenticate(string passwordStored, string passwordInputed) { return(_PasswordService.Check(passwordStored, passwordInputed).Verified); }