Esempio n. 1
0
        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;
            }
        }
Esempio n. 2
0
        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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        //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);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        /// <summary>
        /// Validates the user.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <returns>Task&lt;Domain.Entities.User&gt;.</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);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        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} " }));
                }
            }
        }
Esempio n. 12
0
        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);
            }
        }
Esempio n. 13
0
        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} " }));
                }
            }
        }
Esempio n. 14
0
 public bool Authenticate(string passwordStored, string passwordInputed)
 {
     return(_PasswordService.Check(passwordStored, passwordInputed).Verified);
 }