Esempio n. 1
0
        public string Login(string email, string password)
        {
            LoginUser loginUser = null;

            try
            {
                loginUser = _userOperations.GetLoginUser(email.ToLower());
            }
            catch (NotFoundException)
            {
                throw new AuthenticationException();
            }

            var rehash = Crypto.CalcualteHash(password, loginUser.Salt);

            if (rehash != loginUser.PasswordHash)
            {
                throw new AuthenticationException();
            }

            var userId = loginUser.UserId;

            var user = _userOperations.Get(userId);

            if (!user.Activated)
            {
                throw new ActivationRequiredException();
            }

            _authenticationContext.SetContextUser(userId);

            EnsureEnvironment();

            return(userId);
        }