public HashingConfig GetPossibleConfig(string password, string salt, string saltedPasswordFormat, string inputhash) { var hashConfig = new HashingConfig(); var saltedPassword = GetSaltedPassword(password, salt, saltedPasswordFormat); var algoDet = Hashing.GetAlgoDet(saltedPassword, salt, inputhash); hashConfig.HashingAlgo = algoDet.hashingAlgo; hashConfig.PasswordHashEncodingType = algoDet.encodingType; return(hashConfig); }
public string GetHash(string password, HashingConfig hashConfig) { var salt = hashConfig.GenratePerPasswordSalt ? Hashing.GenerateSalt() : hashConfig.GlobalSalt; var saltedPassword = GetSaltedPassword(password, salt, hashConfig.SaltedPasswordFormat); var passwordHash = Hashing.HashPassword(saltedPassword, salt, hashConfig.HashingAlgo, hashConfig.PasswordHashEncodingType, hashConfig.Pbkdf2Iterations); return(hashConfig.GenratePerPasswordSalt ? $"{passwordHash}:{salt}" : passwordHash); }
public bool CheckPassword(string password, HashingConfig passwordEncryption, string oldPassword) { var saltAndHash = GetSaltAndHash(passwordEncryption, password); var salt = saltAndHash.salt; var passwordHash = saltAndHash.passwordHash; var globalFormattedSalt = saltAndHash.globalFormattedSalt; var saltedPassword = GetSaltedPassword(oldPassword, salt, globalFormattedSalt); var isValidPassword = Hashing.CheckPassword(saltedPassword, salt, passwordHash, passwordEncryption.HashingAlgo, passwordEncryption.PasswordHashEncodingType, passwordEncryption.Pbkdf2Iterations); return(isValidPassword); }
private (string salt, string passwordHash, string globalFormattedSalt) GetSaltAndHash(HashingConfig passwordEncryption, string oldPassword) { var result = (salt : string.Empty, passwordHash : String.Empty, globalFormattedSalt : string.Empty); if (passwordEncryption.GenratePerPasswordSalt) { var idx = oldPassword.LastIndexOf(':'); if (idx != -1) { result.passwordHash = oldPassword.Substring(0, idx); result.salt = oldPassword.Substring(idx + 1); } result.globalFormattedSalt = passwordEncryption.SaltedPasswordFormat; } else { result.passwordHash = oldPassword; result.globalFormattedSalt = passwordEncryption.SaltedPasswordFormat; result.salt = passwordEncryption.GlobalSalt; } return(result); }