public AuthenticationStatus HandleFailedLogin(string username)
        {
            AuthenticationStatus result;

            var user = _db.User.Where(x => x.Username == username).SingleOrDefault();

            var failedCount = (user.LoginAttempts + 1);

            user.LoginAttempts = failedCount;

            if (failedCount >= 3)
            {
                user.IsActive = false;
                result        = AuthenticationStatus.LOCKED_OUT;
            }
            else
            {
                result = AuthenticationStatus.INCORRECT_DETAILS;
            }

            _db.Entry(user).State = EntityState.Modified;
            _db.SaveChanges();

            return(result);
        }
Esempio n. 2
0
        public void UpdatePassword(string username, string password)
        {
            var user = _db.User.Where(x => x.Username == username).SingleOrDefault();

            user.Password         = EncryptPassword.Encode(password);
            _db.Entry(user).State = EntityState.Modified;
            _db.SaveChanges();
        }