Example #1
0
        /// <summary>
        /// Change the account's password.
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public async Task <bool> ChangePassword(string password)
        {
            if (!PasswordVerification.CanBeAPassword(password))
            {
                throw new ArgumentException("Zły format hasła.");
            }

            try
            {
                bool _isPassEqual = CheckOldPassword(password);
                if (_isPassEqual)
                {
                    //If password is the same like that in database and returns false.
                    return(!_isPassEqual);
                }

                return(await SetsNewPassword(password));
            }
            catch (ArgumentNullException)
            {
                throw;
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #2
0
 /// <summary>
 /// Checks password from db and password attempted.
 /// </summary>
 /// <param name="password"></param>
 /// <returns></returns>
 public bool CheckOldPassword(string password)
 {
     try
     {
         return(PasswordVerification.CompareHashedPassword(password, _account.GetAccountPassword(ID)));
     }
     catch (Exception)
     {
         throw;
     }
 }
Example #3
0
        /// <summary>
        /// Sets new Password.
        /// </summary>
        /// <param name="pass"></param>
        /// <returns></returns>
        private async Task <bool> SetsNewPassword(string pass)
        {
            try
            {
                int _res = await _account.SetsNewPassword(ID, PasswordVerification.CreatePasswordHash(pass));

                if (_res == 1)
                {
                    return(true);
                }

                return(false);
            }
            catch (Exception)
            {
                throw;
            }
        }