public static bool ResetSenhaPadrão(ResetPasswordDTO credentials, out IEnumerable <string> validationErrors)
        {
            using (Data.Contexts.SMEManagementContext db = new Contexts.SMEManagementContext())
            {
                User user =
                    (from current in db.Users
                     where current.Name == credentials.Username
                     select current).FirstOrDefault();

                validationErrors = default;

                if (user != null)
                {
                    validationErrors = ValidatePassword(credentials, user);

                    if (validationErrors.Count() < 1)
                    {
                        user.Password = Cryptography.HashPassword(credentials.NewPassword);

                        return(db.SaveChanges() > 0);
                    }
                }

                return(false);
            }
        }
        private static IEnumerable <string> ValidatePassword(ResetPasswordDTO credentials, User user)
        {
            var oldPasswordHash             = Cryptography.HashPassword(credentials.OldPassword);
            var anyUpperCaseLetterPattern   = @"[A-Z]+";
            var anyDigitPattern             = @"\d+";
            var anySpecialCharactertPattern = @"[^a-zA-Z0-9]";

            if (oldPasswordHash != user.Password)
            {
                yield return(PasswordValidationMsgsEnum.WRONG_OLD_PASSWORD.Text);
            }

            if (credentials.NewPassword != credentials.NewPasswordRepeat)
            {
                yield return(PasswordValidationMsgsEnum.PASSWORDS_CONFIRMATION_DIFF.Text);
            }

            if (credentials.NewPassword.Length < 8 || !(Regex.IsMatch(credentials.NewPassword, anyUpperCaseLetterPattern) &&
                                                        Regex.IsMatch(credentials.NewPassword, anyDigitPattern) &&
                                                        Regex.IsMatch(credentials.NewPassword, anySpecialCharactertPattern)))
            {
                yield return(PasswordValidationMsgsEnum.PASSWORD_INSUFFICIENT_COMPLEXITY.Text);
            }

            yield break;
        }
 public static bool ValidateUser(string username, string password)
 {
     using (SMEManagementContextData db = new SMEManagementContextData())
         return(db.Users.Any(x => x.Name == username && x.Password == Cryptography.HashPassword(password)));
 }