public void Correct_Password_Wrong_Encoding_Should_Not_Match(HashingAlgo hashingAlgo) { var originalHashConfig = new HashingConfig { GenratePerPasswordSalt = true, GlobalSalt = null, SaltedPasswordFormat = SaltedPasswordFormat, HashingAlgo = hashingAlgo, PasswordHashEncodingType = EncodingType.Hex }; var mismatchedHashConfig = new HashingConfig { GenratePerPasswordSalt = true, GlobalSalt = null, SaltedPasswordFormat = SaltedPasswordFormat, HashingAlgo = hashingAlgo, PasswordHashEncodingType = EncodingType.Base64 }; var passwordHashing = new PasswordHashing(); var hash = passwordHashing.GetHash(CorrectPassword, originalHashConfig); var match = passwordHashing.CheckPassword(hash, mismatchedHashConfig, CorrectPassword); Assert.False(match); }
public void CustomHashValuesAreInheritedFromDefault() { HashingConfig defaultConfig = HashingConfig.Default; HashingConfig customConfig = new CustomHashingConfig(); Assert.AreEqual(defaultConfig.NumberOfLSHTables, customConfig.NumberOfLSHTables); Assert.AreEqual(defaultConfig.NumberOfMinHashesPerTable, customConfig.NumberOfMinHashesPerTable); }
public HashedFingerprint Hash(Fingerprint fingerprint, HashingConfig hashingConfig) { int numberOfHashTables = hashingConfig.NumberOfLSHTables; int numberOfHashKeysPerTable = hashingConfig.NumberOfMinHashesPerTable; int hashBuckets = hashingConfig.HashBuckets; byte[] subFingerprint = minHashService.Hash(fingerprint.Schema, numberOfHashTables * numberOfHashKeysPerTable); int[] hashBins = GroupIntoHashTables(subFingerprint, numberOfHashTables, numberOfHashKeysPerTable, hashBuckets); return(new HashedFingerprint(hashBins, fingerprint.SequenceNumber, fingerprint.StartsAt, fingerprint.OriginalPoint)); }
public async Task <int> ChangePasswordAsync(string userId, string currentPassword, string newPassword) { var user = await this.FindByIdAsync(userId); if (HashingConfig.VerifyPassword(currentPassword, user.PasswordHash)) { user.PasswordHash = newPassword; user.TimeStamp = DateTime.UtcNow; } return(await this._dbContext.SaveChangesAsync()); }
public async Task <tmIdentityUser> FindAsync(string userName, string password) { var user = await this._dbContext.Users.SingleOrDefaultAsync(u => u.UserName == userName); if (user != null && HashingConfig.VerifyPassword(password, user.PasswordHash)) { return(user); } return(null); }
public HashedFingerprint HashImage(Fingerprint fingerprint, HashingConfig hashingConfig) { int n = hashingConfig.NumberOfLSHTables * hashingConfig.NumberOfMinHashesPerTable; int width = hashingConfig.Width; int height = hashingConfig.Height; var extendedMinHashService = extendedMinHashServices.GetOrAdd(width * height, key => new ExtendedMinHashService(new AdaptivePermutations(n, width, height))); int[] minHashes = extendedMinHashService.Hash(fingerprint.Schema, n); int[] hashed = HashMinHashes(minHashes, hashingConfig.NumberOfLSHTables, hashingConfig.NumberOfMinHashesPerTable); return(new HashedFingerprint(hashed, fingerprint.SequenceNumber, fingerprint.StartsAt, fingerprint.OriginalPoint)); }
public HashedFingerprint Hash(Fingerprint fingerprint, HashingConfig hashingConfig, IEnumerable <string> clusters) { int numberOfHashTables = hashingConfig.NumberOfLSHTables; int numberOfHashKeysPerTable = hashingConfig.NumberOfMinHashesPerTable; int hashBuckets = hashingConfig.HashBuckets; byte[] subFingerprint = minHashService.Hash(fingerprint.Signature, numberOfHashTables * numberOfHashKeysPerTable); return(new HashedFingerprint( GroupIntoHashTables(subFingerprint, numberOfHashTables, numberOfHashKeysPerTable, hashBuckets), fingerprint.SequenceNumber, fingerprint.StartsAt, clusters)); }
public void Wrong_Password_Should_Not_Match(HashingAlgo hashingAlgo) { var hashConfig = new HashingConfig { GenratePerPasswordSalt = false, GlobalSalt = GlobalSalt, SaltedPasswordFormat = SaltedPasswordFormat, HashingAlgo = hashingAlgo, PasswordHashEncodingType = EncodingType.Default }; var passwordHashing = new PasswordHashing(); var hash = passwordHashing.GetHash(CorrectPassword, hashConfig); var match = passwordHashing.CheckPassword(hash, hashConfig, "wrongPassword"); Assert.False(match); }
public void Correct_Password_Should_Match(HashingAlgo hashingAlgo) { var hashConfig = new HashingConfig { GenratePerPasswordSalt = true, GlobalSalt = null, SaltedPasswordFormat = SaltedPasswordFormat, HashingAlgo = hashingAlgo, PasswordHashEncodingType = EncodingType.Default }; var passwordHashing = new PasswordHashing(); var hash = passwordHashing.GetHash(CorrectPassword, hashConfig); var match = passwordHashing.CheckPassword(hash, hashConfig, CorrectPassword); Assert.True(match); }
public void Correct_Hash_Values_Should_Match_GetHash(HashingAlgo hashingAlgo, string expectedHashBase64) { var hashConfig = new HashingConfig { GenratePerPasswordSalt = false, GlobalSalt = GlobalSalt, SaltedPasswordFormat = SaltedPasswordFormat, HashingAlgo = hashingAlgo, PasswordHashEncodingType = EncodingType.Default }; var passwordHashing = new PasswordHashing(); var hashActual = passwordHashing.GetHash(CorrectPassword, hashConfig); var hashExpected = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(expectedHashBase64)); Assert.Equal(hashExpected, hashActual); }
public void Correct_Hash_Values_Should_Match_CheckPassword(HashingAlgo hashingAlgo, string expectedHashBase64) { var hashConfig = new HashingConfig { GeneratePerPasswordSalt = false, GlobalSalt = GlobalSalt, SaltedPasswordFormat = SaltedPasswordFormat, HashingAlgo = hashingAlgo, PasswordHashEncodingType = EncodingType.Default }; var passwordHashing = new PasswordHashing(); var expectedHash = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(expectedHashBase64)); var match = passwordHashing.CheckPassword(expectedHash, hashConfig, CorrectPassword); Assert.True(match); }
public async Task <tmIdentityResult> CreateAsync(string username, string password, string passwordConfirmation) { var user = await UserManager.FindByNameAsync(username); if (user == null) { user = new tmIdentityUser(); user.UserName = username; try { user.PasswordHash = HashingConfig.HashPassword(password); await UserManager.CreateAsync(user); } catch (Exception ex) { return(new tmIdentityResult(ex.Message)); } return(new tmIdentityResult()); } return(new tmIdentityResult("Username already registered")); }
public async Task <int> ChangePasswordAsync(string userId, string currentPassword, string newPassword) { return(await UserManager.ChangePasswordAsync(userId, currentPassword, HashingConfig.HashPassword(newPassword))); }