public void SignUserIn(HttpResponseMessage response, Guid userId, bool rememberMe)
        {
            var user = userStorage.FindUser(userId);

            if (user == null)
            {
                throw new Exception($"Cannot find user {userId}");
            }
            var authenticationToken         = new AuthenticationToken(user.UserId);
            var encryptedBase64EncodedToken = authenticationTokenCryptography.EncryptTokenToBase64(authenticationToken);

            webApiAuthenticationCookieManager.SetTokenCookie(response, encryptedBase64EncodedToken, rememberMe);
        }
예제 #2
0
        public void SignUserIn(HttpContextBase httpContext, Guid userId, bool rememberMe)
        {
            var user = userStorage.FindUser(userId);

            if (user == null)
            {
                throw new Exception(string.Format("Cannot find user {0}", userId));
            }
            var authenticationToken         = new AuthenticationToken(user.UserId);
            var encryptedBase64EncodedToken = authenticationTokenCryptography.EncryptTokenToBase64(authenticationToken);

            authenticationCookieManager.SetTokenCookie(httpContext, encryptedBase64EncodedToken, rememberMe);
        }
예제 #3
0
        public AuthenticationResult <TUser> Authenticate(string login, string password)
        {
            if (string.IsNullOrWhiteSpace(login))
            {
                throw new WrongLoginPasswordException();
            }
            if (string.IsNullOrEmpty(password))
            {
                throw new WrongLoginPasswordException();
            }

            login = login.Trim();

            var user = userStorage.FindUserByLogin(login);

            if (user == null)
            {
                throw new WrongLoginPasswordException();
            }

            if (!user.IsActive)
            {
                throw new InactiveUserException();
            }

            if (string.IsNullOrEmpty(user.PasswordHash) || string.IsNullOrEmpty(user.PasswordSalt))
            {
                throw new UserPasswordNotSetException(user.UserId);
            }

            var passwordHash = passwordHasher.HashPassword(password, user.PasswordSalt);

            if (user.PasswordHash != passwordHash)
            {
                throw new WrongLoginPasswordException();
            }

            var authenticationToken         = new AuthenticationToken(user.UserId);
            var encryptedBase64EncodedToken = authenticationTokenCryptography.EncryptTokenToBase64(authenticationToken);

            return(new AuthenticationResult <TUser>(encryptedBase64EncodedToken, user));
        }