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 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); }