Beispiel #1
0
 public bool Add(User user, UserCredentials userCredentials)
 {
     if (userCredentials.Password == null || userCredentials.Email == null)
     {
         throw new IncorrectDataException("Data not correct");
     }
     if (_userCredentialsRepository.CheckByEmail(userCredentials.Email))
     {
         throw new IncorrectDataException("Email booked");
     }
     if (userCredentials.Role == null)
     {
         userCredentials.Role = "User";
     }
     userCredentials.RegistrationDate = DateTime.Now;
     userCredentials.Password         = SaltedHashGenerator.GenerateHash(userCredentials.Password, userCredentials.Email);
     try
     {
         _userRepository.Add(user, userCredentials);
         return(true);
     }
     catch (DbEntityValidationException ex)
     {
         throw new IncorrectDataException(DbEntityValidationExceptioErrorMessages.ErrorMessages(ex));
     }
 }
 public bool EditPassword(int id, string newPassword, string oldPassword)
 {
     try
     {
         UserCredentials userCredentials = _userCredentialsRepository.GetById(id);
         string          oldP            = SaltedHashGenerator.GenerateHash(oldPassword, userCredentials.Email);
         if (oldP != userCredentials.Password)
         {
             throw new IncorrectDataException("Passwords do not match");
         }
         _userCredentialsRepository.EditPassword(id, newPassword);
         return(true);
     }
     catch (DbEntityValidationException ex)
     {
         throw new IncorrectDataException(DbEntityValidationExceptioErrorMessages.ErrorMessages(ex));
     }
 }
        public UserCredentials GetByEmailAndPassword(string email, string password)
        {
            string hashPassword = SaltedHashGenerator.GenerateHash(password, email);

            return(_userCredentialsRepository.GetByEmailAndPassword(email, hashPassword));
        }