Esempio n. 1
0
        public async Task <SignInResult> TwoFactorRecoveryCodeSignInAsync(string recoveryCode)
        {
            var twoFactorInfo = await RetrieveTwoFactorInfoAsync();

            if (twoFactorInfo == null || twoFactorInfo.UserId == null)
            {
                return(SignInResult.Failed);
            }

            var model = new RedeemTwoFactorRecoveryCodeModel
            {
                UserId       = twoFactorInfo.UserId,
                RecoveryCode = recoveryCode
            };

            var result = await _accountsEndpoint.RedeemTwoFactorRecoveryCodeAsync(model);

            if (result.Succeeded)
            {
                await DoTwoFactorSignInAsync(twoFactorInfo.UserId, false);

                return(SignInResult.Success);
            }

            // We don't protect against brute force attacks since codes are expected to be random.
            return(SignInResult.Failed);
        }
Esempio n. 2
0
 public async Task <RedeemTwoFactorRecoveryCodeModel> RedeemTwoFactorRecoveryCodeAsync(RedeemTwoFactorRecoveryCodeModel model)
 {
     return(await _apiHelper.PostAsync(model, "api/Account/RedeemTwoFactorRecoveryCode"));
 }
Esempio n. 3
0
        public async Task <RedeemTwoFactorRecoveryCodeModel> RedeemTwoFactorRecoveryCode(RedeemTwoFactorRecoveryCodeModel model)
        {
            var user = await _userManager.FindByIdAsync(model.UserId);

            if (user == null)
            {
                model.Succeeded = false;
                return(model);
            }
            var result = await _userManager.RedeemTwoFactorRecoveryCodeAsync(user, model.RecoveryCode);

            model.Succeeded = result.Succeeded;

            return(model);
        }