Пример #1
0
        public void TestHashVerification()
        {
            var passwordHash = Cryptonite.Hash("Benjamin");

            const string correctPassword   = "******";
            const string incorrectPassword = "******";

            Assert.True(Cryptonite.Verify(correctPassword, passwordHash));
            Assert.False(Cryptonite.Verify(incorrectPassword, passwordHash));
        }
Пример #2
0
        public string GetToken(string username, string password)
        {
            var user = _authContext.Users.FirstOrDefault(u => u.Username.Equals(username));

            if (user == null)
            {
                return(null);
            }
            if (!Cryptonite.Verify(password, user.PasswordHash))
            {
                return(null);
            }
            if (Tokenizer.VerifyTimestampedToken(user.Token))
            {
                return(user.Token);
            }

            user.Token = Tokenizer.CreateTimestampedToken();
            _authContext.SaveChanges();

            return(user.Token);
        }