static void Main(string[] args) { string basePath = $"{Directory.GetParent(Directory.GetCurrentDirectory()).Parent.Parent.FullName}\\Data"; List <string> top100Passwords = File.ReadAllLines($"{basePath}\\top_100.txt") .SelectMany(line => line.Split(" ", StringSplitOptions.RemoveEmptyEntries).TakeLast(1).Select(s => s.Trim())) .ToList(); List <string> top100000Passwords = File.ReadAllLines($"{basePath}\\top_100000.txt") .Select(line => line.Trim()) .ToList(); var passwordGenerator = new PasswordsGenerator(top100Passwords, top100000Passwords); int passwordsPerFile = 100_000; BaseHasher hasher = new MD5Hasher(); //passwordGenerator.GeneratePasswords(passwordsCount: passwordsPerFile) // .Select(p => hasher.GetHashedRecord(p)) // .WriteListToCsvFile($"{basePath}\\md5_hashed.csv"); //hasher = new SHA1Hasher(); //passwordGenerator.GeneratePasswords(passwordsCount: passwordsPerFile) // .Select(p => hasher.GetHashedRecord(p)) // .WriteListToCsvFile($"{basePath}\\sha1_hashed.csv"); hasher = new Argon2idHasher(); passwordGenerator.GeneratePasswords(passwordsCount: passwordsPerFile) .ForEach(p => hasher.GetHashedRecord(p).AppendRecordToCsvFile($"{basePath}\\argon2id_hashed.csv")); }
public void HashPasswordTest() { const string password = "******"; var hasher = new Argon2idHasher(); var hash1 = hasher.HashFromPassword(password); var hash2 = hasher.HashFromPassword(password); Assert.IsNotEmpty(hash1); Assert.IsNotEmpty(hash2); Assert.AreNotEqual(hash1, hash2); Assert.Throws <ArgumentException>(() => hasher.HashFromPassword("")); Assert.Throws <ArgumentNullException>(() => hasher.HashFromPassword(null)); }
public void CompareHashAndPasswordTest() { const string password = "******"; const string wrongPassword = "******"; var hasher = new Argon2idHasher(); var hash = hasher.HashFromPassword(password); Assert.IsTrue(hasher.CompareHashAndPassword(hash, password)); Assert.IsFalse(hasher.CompareHashAndPassword(hash, wrongPassword)); Assert.Throws <ArgumentException>(() => hasher.CompareHashAndPassword(hash, "")); Assert.Throws <ArgumentException>(() => hasher.CompareHashAndPassword("", password)); Assert.Throws <ArgumentNullException>(() => hasher.CompareHashAndPassword(hash, null)); Assert.Throws <ArgumentNullException>(() => hasher.CompareHashAndPassword(null, hash)); }