using System.Diagnostics; using Sodium; using PlanTempus.Core; namespace PlanTempus.Tests { [TestClass] public class PasswordHasherTests : TestFixture { [TestMethod] public void MyTestMethod() { var stopwatch = Stopwatch.StartNew(); byte[] salt = PasswordHash.ScryptGenerateSalt(); // 2. Konverter password til byte[] byte[] passwordBytes = System.Text.Encoding.UTF8.GetBytes("password123"); // 3. Kald ScryptHashBinary korrekt byte[] hash = PasswordHash.ScryptHashBinary( password: passwordBytes, salt: salt, // 32-byte array limit: PasswordHash.Strength.Interactive, outputLength: 32 ); stopwatch.Stop(); } [TestMethod] public void HashPassword_ShouldCreateValidHashFormat() { // Arrange string password = "TestPassword123"; // Act string hashedPassword = new SecureTokenizer().TokenizeText(password); string[] parts = hashedPassword.Split('.'); // Assert Assert.AreEqual(3, parts.Length); Assert.AreEqual("100000", parts[0]); } [TestMethod] public void VerifyPassword_WithCorrectPassword_ShouldReturnTrue() { // Arrange string password = "TestPassword123"; string hashedPassword = new SecureTokenizer().TokenizeText(password); // Act bool result = new SecureTokenizer().VerifyToken(hashedPassword, password); // Assert Assert.IsTrue(result); } [TestMethod] public void VerifyPassword_WithWrongPassword_ShouldReturnFalse() { // Arrange string correctPassword = "TestPassword123"; string wrongPassword = "WrongPassword123"; string hashedPassword = new SecureTokenizer().TokenizeText(correctPassword); // Act bool result = new SecureTokenizer().VerifyToken(hashedPassword, wrongPassword); // Assert Assert.IsFalse(result); } [TestMethod] public void VerifyPassword_WithInvalidHashFormat_ShouldReturnFalse() { // Arrange string password = "TestPassword123"; string invalidHash = "InvalidHash"; // Act bool result = new SecureTokenizer().VerifyToken(invalidHash, password); // Assert Assert.IsFalse(result); } } }