/// <summary> /// Registers a Hash Digest Computation Method. /// </summary> /// <param name="HashComputationMethod">Hash Digest Computation Method.</param> /// <param name="HashMethodTypeName">Hash Digest Computation Method Type Name.</param> /// <param name="LoginAuditor">Auditor of login attempts.</param> /// <param name="Lock">If the registration should be locked.</param> public static void Register(HashComputationMethod HashComputationMethod, string HashMethodTypeName, LoginAuditor LoginAuditor, bool Lock) { if (hashMethodLocked) { throw new InvalidOperationException("Hash method already registered, and locked."); } loginAuditor = LoginAuditor; hashMethod = HashComputationMethod; hashMethodTypeName = HashMethodTypeName; hashMethodLocked = Lock; }
/// <summary> /// Computes a hash of a password. /// </summary> /// <param name="UserName">User name.</param> /// <param name="Password">Password.</param> public static byte[] ComputeHash(string UserName, string Password) { HashComputationMethod h = hashMethod; if (h is null) { return(Hashes.ComputeSHA256Hash(Encoding.UTF8.GetBytes(UserName + ":" + Password))); } else { return(h(UserName, Password)); } }