public void CreateToken()
        {
            Token token = new Token("peter",  "127.0.0.1");
            string encrypted = token.Encrypt();

            Token recreatedToken = Token.Decrypt(encrypted);

            Assert.AreEqual(token.UserId, recreatedToken.UserId);
            Assert.AreEqual(token.IP, recreatedToken.IP);
        }
        public Status Authenticate(User user)
        {
            if (user == null)
                throw new HttpResponseException(new HttpResponseMessage() { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("Please provide the credentials.") });

            if (IdentityStore.IsValidUser(user))
            {
                Token token = new Token(user.UserId, Request.GetClientIP());
                return new Status { Successeded = true, Token = token.Encrypt(), Message = "Successfully signed in." };
            }
            else
            {
                throw new HttpResponseException(new HttpResponseMessage() { StatusCode = HttpStatusCode.Unauthorized, Content = new StringContent("Invalid user name or password.") });
            }
        }