Esempio n. 1
0
        public Result <LogInResponse> LogIn(LogInRequest request)
        {
            if (string.IsNullOrEmpty(request.Email) || string.IsNullOrEmpty(request.Password))
            {
                return(new Result <LogInResponse>(false, "Bad request received."));
            }

            var userResult = _accountAccessor.FindUserByEmail(request.Email);

            if (!userResult.IsSuccess)
            {
                return(new Result <LogInResponse>(false, "The email/password combination you entered is incorrect."));
            }
            var password       = _accountAccessor.GetUserPassword(userResult.Payload.UserID).Payload;
            var hashedPassword = _encryptionService.CreatePasswordHash(request.Password, password.PasswordSalt);

            if (hashedPassword == password.Password)
            {
                var result = _accountAccessor.CreateLogInResponse(userResult.Payload.UserID);
                result.Payload.CartItems = _donateService.CheckCart(userResult.Payload.UserID);
                return(result);
            }
            else
            {
                return(new Result <LogInResponse>(false, "The email/password combination you entered is incorrect."));
            }
        }
Esempio n. 2
0
        public Result ChangePassword(int userID, string currentPassword, string newPassword)
        {
            if (string.IsNullOrEmpty(currentPassword) || string.IsNullOrEmpty(newPassword))
            {
                return(new Result(false, "Bad request received."));
            }

            var passwordResult = _accountAccessor.GetUserPassword(userID);

            if (!passwordResult.IsSuccess)
            {
                return(new Result(false, "User not found."));
            }

            var password       = passwordResult.Payload;
            var hashedPassword = _encryptionService.CreatePasswordHash(currentPassword, password.PasswordSalt);

            if (hashedPassword == password.Password)
            {
                var newSaltKey        = _encryptionService.CreateSaltKey(Convert.ToInt32(_configuration["PasswordSaltLength"]));
                var newHashedPassword = _encryptionService.CreatePasswordHash(newPassword, newSaltKey);
                _accountAccessor.ChangePassword(userID, newHashedPassword, newSaltKey);
                return(new Result(true));
            }
            else
            {
                return(new Result(false, "Current password was incorrect."));
            }
        }