コード例 #1
0
        public IActionResult Get(string secret)
        {
            if (string.IsNullOrEmpty(secret))
            {
                return(BadRequest());
            }

            return(new ObjectResult(string.Format("{0:000000}", _service.GetCode(HashAlgorithmType.SHA1, Encoding.UTF8.GetBytes(secret), 6, 30))));
        }
コード例 #2
0
        private bool ValidateAuthenticatorCode(string code, HashAlgorithmType hashAlgorithm, byte[] secret, byte numberOfDigits, byte periodInSeconds)
        {
            int codeParsed;

            if (!code.TryParseAndRemoveWhiteSpace(out codeParsed))
            {
                return(false);
            }

            var expectedCode = _authenticatorService.GetCode(hashAlgorithm, secret, numberOfDigits, periodInSeconds);

            return(expectedCode == codeParsed);
        }
コード例 #3
0
        public async Task <bool> ValidateAsync(string purpose, string token, UserManager <TUser> manager, TUser user)
        {
            int code;

            if (!token.TryParseAndRemoveWhiteSpace(out code))
            {
                return(false);
            }

            var authenticatorParams = await GetAuthenticatorUserManager(manager).GetAuthenticatorParamsAsync(user);

            var execpectedCode = _authenticationService.GetCode(
                authenticatorParams.HashAlgorithm,
                authenticatorParams.Secret,
                authenticatorParams.NumberOfDigits,
                authenticatorParams.PeriodInSeconds);

            return(code == execpectedCode);
        }