コード例 #1
0
        public bool ValidateRecoveryCode(string code, IMultiFactorSettings mfa)
        {
            var otps = this.ToHotp(mfa);
            var otp  = new OtpGenerator(otps);

            return(otp.Generate(offset: mfa.RecoveryTripCount) == code);
        }
コード例 #2
0
        public bool ValidateCode(string code, IMultiFactorSettings mfa)
        {
            var otps = this.ToTotp(mfa);
            var otp  = new OtpGenerator(otps);

            return(otp.GenerateWindow().Contains(code));
        }
コード例 #3
0
        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
            });
        }
コード例 #4
0
        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);
                }
            }
        }
コード例 #5
0
 private OtpGeneratorSettings ToTotp(IMultiFactorSettings mfa)
 => mfa.Type switch
 {