예제 #1
0
        /// <summary>
        /// Verify an OTP value
        /// </summary>
        /// <param name="initialStep">The initial step to try</param>
        /// <param name="valueToVerify">The value to verify</param>
        /// <param name="matchedStep">Output parameter that provides the step where the match was found.  If no match was found it will be 0</param>
        /// <param name="window">The window to verify</param>
        /// <returns>True if a match is found</returns>
        protected bool Verify(long initialStep, string valueToVerify, out long matchedStep, VerificationWindow window)
        {
            if (window == null)
            {
                window = new VerificationWindow();
            }
            foreach (var frame in window.ValidationCandidates(initialStep))
            {
                var comparisonValue = this.Compute(frame, this.hashMode);
                if (ValuesEqual(comparisonValue, valueToVerify))
                {
                    matchedStep = frame;
                    return(true);
                }
            }

            matchedStep = 0;
            return(false);
        }
예제 #2
0
        private bool VerifyTotpForSpecificTime(DateTime timestamp, string totp, VerificationWindow window, out long timeStepMatched)
        {
            var initialStep = CalculateTimeStepFromTimestamp(timestamp);

            return(this.Verify(initialStep, totp, out timeStepMatched, window));
        }
예제 #3
0
 /// <summary>
 /// Verify a value that has been provided with the calculated value
 /// </summary>
 /// <param name="timestamp">The timestamp to use</param>
 /// <param name="totp">the trial TOTP value</param>
 /// <param name="timeStepMatched">
 /// This is an output parameter that gives that time step that was used to find a match.
 /// This is usefule in cases where a TOTP value should only be used once.  This value is a unique identifier of the
 /// time step (not the value) that can be used to prevent the same step from being used multiple times
 /// </param>
 /// <param name="window">The window of steps to verify</param>
 /// <returns>True if there is a match.</returns>
 public bool VerifyTotp(DateTime timestamp, string totp, out long timeStepMatched, VerificationWindow window = null)
 {
     return(this.VerifyTotpForSpecificTime(this.correctedTime.GetCorrectedTime(timestamp), totp, window, out timeStepMatched));
 }
예제 #4
0
 /// <summary>
 /// Verify a value that has been provided with the calculated value.
 /// </summary>
 /// <remarks>
 /// It will be corrected against a corrected UTC time using the provided time correction.  If none was provided then simply the current UTC will be used.
 /// </remarks>
 /// <param name="totp">the trial TOTP value</param>
 /// <param name="timeStepMatched">
 /// This is an output parameter that gives that time step that was used to find a match.
 /// This is useful in cases where a TOTP value should only be used once.  This value is a unique identifier of the
 /// time step (not the value) that can be used to prevent the same step from being used multiple times
 /// </param>
 /// <param name="window">The window of steps to verify</param>
 /// <returns>True if there is a match.</returns>
 public bool VerifyTotp(string totp, out long timeStepMatched, VerificationWindow window = null)
 {
     return(this.VerifyTotpForSpecificTime(this.correctedTime.CorrectedUtcNow, totp, window, out timeStepMatched));
 }