public static void Configure()
        {
            CurrentAlgorithm =
                ServerConfiguration.GetOrUpdateSetting("accountSecurity.encryptionAlgorithm", PasswordProtectionAlgorithm.Argon2);

            if (CurrentAlgorithm < PasswordProtectionAlgorithm.SHA2)
            {
                throw new Exception($"Security: {CurrentAlgorithm} is obsolete and not secure. Do not use it.");
            }
        }
Example #2
0
        public static IPasswordProtection GetPasswordProtection(PasswordProtectionAlgorithm algorithm)
        {
            var passwordProtection = algorithm switch
            {
                PasswordProtectionAlgorithm.MD5 => HashAlgorithmPasswordProtection.MD5Instance,
                PasswordProtectionAlgorithm.SHA1 => HashAlgorithmPasswordProtection.SHA1Instance,
                PasswordProtectionAlgorithm.SHA2 => HashAlgorithmPasswordProtection.SHA2Instance,
                PasswordProtectionAlgorithm.PBKDF2 => PBKDF2PasswordProtection.Instance,
                PasswordProtectionAlgorithm.Argon2 => Argon2PasswordProtection.Instance,
                PasswordProtectionAlgorithm.None => throw new Exception("Do not use PasswordProtectionAlgorithm.None"),
                      _ => throw new Exception("No algorithm")
            };

            return(passwordProtection);
        }
    }