Esempio n. 1
0
        public bool VerifyOtp(string code, byte[] challenge = null, int forward = 1, int back = 1)
        {
            if (string.IsNullOrEmpty(code) || code.Length != CodeLength || (CachingProvider != null && !CachingProvider.ValidateToken(code)))
            {
                return(false);
            }
            long          State = GetState(-back);
            List <string> Tried = new List <string>();

            for (int I = 0; I <= (forward + back); I++)
            {
                string Code = GetOtp(state: State + I, challenge: challenge);
                Tried.Add(code);
                if (Code == code)
                {
                    if (CachingProvider != null)
                    {
                        CachingProvider.CancelTokens(Type, Tried);
                    }
                    if (Type == OtpType.HOTP)
                    {
                        HotpCounter = State + I + 1;
                    }
                    return(true);
                }
            }
            return(false);
        }