Beispiel #1
0
        public HashingService(IAccountCredentials credentials)
        {
            credentials.TryValidate();
            _Salt  = credentials.EmailAddress;
            _Input = credentials.PlainTextPassword;

            SetParameters();
        }
        /// <exception cref="KeyNotFoundException">If the account is not found</exception>
        public IAccount Update(IAccountCredentials credentials)
        {
            var account = (Account)Find(credentials.EmailAddress);

            account.ApplyNewCredentials(credentials);
            account.Id = new Account_Update(account, _ConnectionString).ExecuteNonQuery();

            return(account);
        }
        /// <exception cref="NotSupportedException">If the account already exists</exception>
        public IAccount Insert(IAccountCredentials credentials)
        {
            try
            {
                Find(credentials.EmailAddress);
                throw new NotSupportedException();
            }
            catch (KeyNotFoundException)
            {
                var account = new Account(credentials);
                account.Id = new Account_Insert(account, _ConnectionString).ExecuteNonQuery();

                return(account);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Confirms that the email address and password have been set
        /// </summary>
        /// <param name="credentials"></param>
        /// <returns>validated credentials</returns>
        /// <exception cref="ArgumentNullException">if null or empty</exception>
        public static bool TryValidate(this IAccountCredentials credentials)
        {
            if (string.IsNullOrEmpty(credentials?.EmailAddress) ||
                string.IsNullOrEmpty(credentials?.PlainTextPassword))
            {
                throw new ArgumentNullException();
            }

            if (!credentials.EmailAddressIsValid ||
                !credentials.PlainTextPasswordIsValid)
            {
                throw new ArgumentOutOfRangeException();
            }

            return(true);
        }
 public IAccount Find(IAccountCredentials credentials)
 {
     credentials.TryValidate();
     return(Find(credentials.EmailAddress));
 }
Beispiel #6
0
 /// <param name="credentials"></param>
 /// <returns>a salted hash of the password</returns>
 public static string HashPassword(IAccountCredentials credentials)
 {
     return(new HashingService(credentials).Execute());
 }
Beispiel #7
0
 public static string HashPassword(this IAccountCredentials credentials)
 {
     return(HashingService.HashPassword(credentials));
 }