public bool ValidateRecoveryCode(string code, IMultiFactorSettings mfa) { var otps = this.ToHotp(mfa); var otp = new OtpGenerator(otps); return(otp.Generate(offset: mfa.RecoveryTripCount) == code); }
public bool ValidateCode(string code, IMultiFactorSettings mfa) { var otps = this.ToTotp(mfa); var otp = new OtpGenerator(otps); return(otp.GenerateWindow().Contains(code)); }
public MfaSettingsModel GenerateClientData(IMultiFactorSettings mfa, string label, string issuer, string continuation) { var otps = new TotpGeneratorSettings(label, issuer, mfa.Secret, ByteEncoding.Base32, (HmacAlgorithm)mfa.HmacAlgorithm, mfa.Digits, mfa.Additional, mfa.Period); var uri = otps.ToUri().OriginalString; return(new MfaSettingsModel { AuthenticatorUri = uri, RecoveryCodes = this.GenerateRecoveryCodes(mfa), Continuation = continuation }); }
public IEnumerable <string> GenerateRecoveryCodes(IMultiFactorSettings mfa) { var recs = this.ToHotp(mfa); var otp = new OtpGenerator(recs); for (var i = 0; i < 10; i++) { var code = otp.Generate(groupSize: 4); if (i >= mfa.RecoveryTripCount) { yield return(code); } } }
private OtpGeneratorSettings ToTotp(IMultiFactorSettings mfa) => mfa.Type switch {