public string AddUser(AccountPassword accountPassword)
        {
            var token = _sessionIdProvider.GetSessionId();

            var authenticationSession = new AuthenticationSession(accountPassword.Account, token,
                                                                  _nowProvider.Now);

            _authenticationSessionRepository.Add(authenticationSession);

            return(token);
        }
        public bool TryAuthenticate(string emailAddress, string password, out ServiceLoginToken token)
        {
            AccountPassword accountPassword = _accountPasswords.GetByEmail(emailAddress);

            if (accountPassword == null)
            {
                token = null;
                return(false);
            }

            if (accountPassword.Password != password)
            {
                token = null;
                return(false);
            }

            var tokenStr = _sessionIdProvider.GetSessionId();
            var authenticationSession = new AuthenticationSession(accountPassword.Account, tokenStr,
                                                                  _nowProvider.Now);

            _authenticationSessionRepository.Add(authenticationSession);
            token = new ServiceLoginToken(tokenStr, accountPassword.Account.Id);
            return(true);
        }
 private bool TokenExpired(AuthenticationSession session, DateTime now)
 {
     return(now.Subtract(session.LastValidation) > _sessionTimeOut);
 }