コード例 #1
0
            public static void GenerateCorrectPasswordWithCorrectNumberOfDigitsAsSpecifiedInParameters(
                string secrect, int digits, DateTime now, AuthenticatorAlgorithm authenticatorAlgorithm, string expectedPassword)
            {
                expectedPassword = expectedPassword.Substring(expectedPassword.Length - digits);

                var authenticator  = new Authenticator(options => options.AuthenticatorAlgorithm = authenticatorAlgorithm);
                var actualPassword = authenticator.GenerateTimeBasedPassword(secrect, () => now, digits, 30);

                Assert.Equal(expectedPassword, actualPassword);
            }
コード例 #2
0
            public static void GenerateCorrectSixDigitPasswordWith30SecondsStepByDefaultIfDigitsAndTimeStepParametersAreNotSpecified(
                string secrect, int digits, DateTime now, AuthenticatorAlgorithm authenticatorAlgorithm, string expectedPassword)
            {
                expectedPassword = expectedPassword.Substring(expectedPassword.Length - digits);

                var authenticator  = new Authenticator(options => options.AuthenticatorAlgorithm = authenticatorAlgorithm);
                var actualPassword = authenticator.GenerateTimeBasedPassword(secrect, () => now);

                Assert.Equal(expectedPassword, actualPassword);
            }
コード例 #3
0
            public static void GenerateCorrectPasswordWithCorrectNumberOfDigitsAsSpecifiedInOptions(
                string secrect, int digits, DateTime now, AuthenticatorAlgorithm authenticatorAlgorithm, string expectedPassword)
            {
                expectedPassword = expectedPassword.Substring(expectedPassword.Length - digits);

                var authenticator = new Authenticator(options =>
                {
                    options.AuthenticatorAlgorithm = authenticatorAlgorithm;
                    options.NumberOfPasswordDigits = digits;
                    options.SizeOfTimeStep         = 30;
                });
                var actualPassword = authenticator.GenerateTimeBasedPassword(secrect, () => now);

                Assert.Equal(expectedPassword, actualPassword);
            }
コード例 #4
0
            public static void ThrowInvalidOperationExceptionIfAuthenticatorAlgorithmIsNotHMACSHA1(AuthenticatorAlgorithm authenticatorAlgorithm)
            {
                var authenticator = new Authenticator(options => options.AuthenticatorAlgorithm = authenticatorAlgorithm);

                Assert.Throws <InvalidOperationException>(() => authenticator.GenerateCounterBasedPassword(Secret, 9));
            }