public void TestHashEquality()
        {
            var ben        = Cryptonite.Hash("Ben");
            var anotherBen = Cryptonite.Hash("Ben");

            TestContext.Out.WriteLine(ben);
            Assert.AreNotEqual(ben, anotherBen);
        }
        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));
        }
 public UserProfile()
 {
     CreateMap <CreateUserRequest, User>()
     .ForMember(dest => dest.PasswordHash,
                opt =>
                opt.MapFrom(src => Cryptonite.Hash(src.Password)))
     .ForMember(dest => dest.Token,
                opt =>
                opt.MapFrom(src => Tokenizer.CreateTimestampedToken()));
 }
        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);
        }