示例#1
0
        public async Task <ActionResult> Validate()
        {
            var user = await this.UserManager.FindByIdAsync(this.User.Identity.GetUserId());

            var model = new ValidateTotpViewModel {
                IsTotpEnabled = user.IsTotpEnabled()
            };

            return(this.View(model));
        }
示例#2
0
        public async Task <ActionResult> Validate(ValidateTotpViewModel model)
        {
            if (this.ModelState.IsValid)
            {
                var user = await this.UserManager.FindByIdAsync(this.User.Identity.GetUserId());

                model.IsTotpEnabled = user.IsTotpEnabled();
                var  totp = new Totp(user.TotpSecretKey);
                long timeStep;
                model.CodeIsValid     = totp.VerifyTotp(model.Code, out timeStep, new VerificationWindow(2, 2));
                model.TimeStepMatched = timeStep;
            }

            return(this.View(model));
        }