ASP.Net身份短信2重置密码 [英] ASP.Net Identity 2 Reset password with SMS

查看:329
本文介绍了ASP.Net身份短信2重置密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找CH375复位自己的密码时,向用户发送短信。我已经有设施,以发送短信,我只需要对如何使用Identity 2.0设置它的指南。我似乎无法在网上找到任何有用的信息,参考code本身没有正确或者评论

I'm looking to send the user an SMS when reseting their password. I already have the facilities to send a SMS, I just need a guide on how to set it up with Identity 2.0. I can't seem to find any useful info online, the reference code itself isn't properly commented either.

我想要生成安全code,将它发送给用户,他必须再输入它变成一个表格,然后被允许复位他/她的密码。任何人都可以直接我的指南/教程解释了这个过程吗?

I want to generate a security code, send it to the user, he must then input it into a form and then be allowed to reset his/her password. Can anyone direct me to a guide/tutorial that explains this process?

推荐答案

在身份源$ C ​​$ C挖后,我发现一个替代的令牌供应商,可以产生类似电话号码的确认(六位数字)。

After digging in the identity source code i found an alternative token provider that can generate tokens similar to phone number confirmation (six digits).

我不得不实施在我的UserManager两种方法来产生code,然后对其进行验证。

I had to implement two methods in my UserManager to generate the code and then to validate it.

我宣布的UserManager

I declared the token provider inside the UserManager

private TotpSecurityStampBasedTokenProvider<User, string> smsResetTokenProvider = new TotpSecurityStampBasedTokenProvider<User, string>();

这是产生code中的第一种方法:

This is the first method to generate the code:

public async Task<string> GenerateSMSPasswordResetToken(string userId)
    {
        var user = await base.FindByIdAsync(userId);
        var token = await smsResetTokenProvider.GenerateAsync("Reset Password", this, user);
        return token;
    }

这是验证code中的第二种方法:

This is the second method to validate the code:

public async Task<IdentityResult> SMSPasswordResetAsync(string userId, string token, string newPassword)
    {
        var user = await base.FindByIdAsync(userId);
        var valid = await smsResetTokenProvider.ValidateAsync("Reset Password", token, this, user);
        if (valid)
        {
            var passwordStore = Store as IUserPasswordStore<User, string>;

            var result = await UpdatePassword(passwordStore, user, newPassword);
            if (!result.Succeeded)
            {
                return result;
            }
            return await UpdateAsync(user);
        }
        else
        {
            return IdentityResult.Failed("InvalidToken");
        }
    }

您可能需要调整code取决于你的用户管理器

You may need to tweak the code depending on your user manager

这篇关于ASP.Net身份短信2重置密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆