public async Task <IMultiFactorSettings> GenerateMfaAsync(IMfaRepository mfaRepository, long userId, bool generateAdditional, CancellationToken cancellationToken = default) { var recbase = 0L; using (var rng = new SecureRandom()) recbase = rng.GetInt64(); var totp = TotpGeneratorSettings.GenerateGoogleAuthenticator(null, null); return(await mfaRepository.ConfigureMfaAsync(userId, totp.Secret.ToArray(), totp.Digits, (MultiFactorHmac)totp.Algorithm, totp.Period, MultiFactorType.Google, null, recbase, cancellationToken)); }
/// <summary> /// Creates new Google Authenticator-compatible settings, and generates a new secret. /// </summary> /// <param name="label">Label for the generator.</param> /// <param name="issuer">Issuer for the generator.</param> /// <returns>Created generator settings.</returns> public static HotpGeneratorSettings GenerateGoogleAuthenticator(string label, string issuer) { var secret = new byte[160 / 8]; long counter; using (var rng = new SecureRandom()) { rng.GetBytes(secret); counter = rng.GetInt64(); } return CreateGoogleAuthenticator(label, issuer, secret, counter); }