Asp.Net Identity SMS验证令牌永远无效

时间:2016-02-15 08:53:27

标签: asp.net asp.net-identity

我尝试使用ASP.Net Identity验证电话号码。

这是我的代码生成:

        public async Task<JsonResult> SendVerifyPhoneNumber()
    {
        var user = await this.UserManager.FindByIdAsync(User.Identity.GetUserId<int>());
        if (user != null)
        {
            if (!string.IsNullOrWhiteSpace(user.PhoneNumber))
            {
                if (!await this.UserManager.IsPhoneNumberConfirmedAsync(user.Id))
                {
                    string number = user.PhoneNumber;
                    if (!string.IsNullOrWhiteSpace(number))
                    {
                        number = TelNumber.DecryptUserTelefon(number, ApplicationUser.AES_CRYPTO_KEY);
                    }
                    string code = await this.UserManager.GenerateChangePhoneNumberTokenAsync(user.Id, number);
                    string text = string.Format(ResourcesLocal.Resources_Manage_Index.TelefoncodeNachrichtBestaetigen, code);
                    bool result = Helper.Services.SmsService.SendSMS(SmSWarteschlangeCon, number, text);
                }
            }

            return Json(true);
        }

        return Json(false);
    }

我的代码在哪里通过输入捕获:

    public async Task<JsonResult> VerifyPhoneNumber(string code)
    {
        var user = await this.UserManager.FindByIdAsync(User.Identity.GetUserId<int>());
        if (user != null)
        {
            string number = user.PhoneNumber;
            if (!string.IsNullOrWhiteSpace(number))
            {
                number = TelNumber.EncryptUserTelefon(number, ApplicationUser.AES_CRYPTO_KEY);
            }
            var result = await this.UserManager.ChangePhoneNumberAsync(
                        user.Id, number, code);
            if (result.Succeeded)
            {
                user = await this.UserManager.FindByIdAsync(user.Id);
                if (user != null)
                {
                    await this.SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                }
                return Json(true);
            }

        }
        return Json(false);
    }

但是每次使用“无效令牌”时结果都会失败,即使代码相同并在几秒钟内给出......

有什么想法吗?

0 个答案:

没有答案