/// <summary>
        /// Logins the specified user name.
        /// </summary>
        /// <param name="password">The users password.</param>
        /// <returns></returns>
        public bool Login(string password)
        {
            bool result = false;

            MasterSecret masterSecret   = _passwordRepository.GetMasterSecret(_cMasterSecretName);
            string       hashedPassword = _securityService.HashData(password).Result;

            if (hashedPassword == masterSecret.Password)
            {
                result = true;
            }
            else
            {
                if (masterSecret.NumberOfAttemptsLeft > 0)
                {
                    masterSecret.NumberOfAttemptsLeft -= masterSecret.NumberOfAttemptsLeft;
                }
                else
                {
                    masterSecret.NumberOfAttemptsLeft = _cMaxNumberOfAttempts;
                }
            }

            return(result);
        }
Exemplo n.º 2
0
        public MasterSecret GetMasterSecret(string name)
        {
            MasterSecretOrm masterSecretOrm = dbHelper.GetMasterSecret(name);
            MasterSecret    result          = masterSecretOrm.Map <MasterSecretOrm, MasterSecret>();

            return(result);
        }
Exemplo n.º 3
0
        public async Task <MasterSecret> SaveMasterSecret(MasterSecret masterSecret)
        {
            MasterSecretOrm masterSecretOrm = masterSecret.Map <MasterSecret, MasterSecretOrm>();

            dbHelper.UpdateMasterSecret(masterSecretOrm);

            return(await Task.FromResult(masterSecret));
        }
        /// <summary>
        /// Set the master password.
        /// </summary>
        /// <param name="password">The master password.</param>
        public void SetMasterPassword(string password)
        {
            string hashedPassword = _securityService.HashData(password).Result;

            MasterSecret masterSecret = new MasterSecret()
            {
                Name                 = _cMasterSecretName,
                Password             = hashedPassword,
                NumberOfAttemptsLeft = _cMaxNumberOfAttempts,
                LastAttempt          = DateTime.Now,
                NumberOfAttemptsLeftBeforeLockout = _cMaxNumberOfAttemptsBeforeLockedOut
            };

            _passwordRepository.SaveMasterSecret(masterSecret);
        }