如何允许我的用户在Cognito用户池上重设密码? [英] How to allow my user to reset their password on Cognito User Pools?

查看:194
本文介绍了如何允许我的用户在Cognito用户池上重设密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,在我的应用中,我显然希望为用户提供重设密码的方法。但我遇到的问题是,有关用户池的新文档在该主题上模棱两可。这是他们告诉您为忘记密码流程执行的操作,您可以在以下链接找到它:

So in my app I obviously want to provide the means for users to reset their passwords. The issue I'm having though is that the new documentation for User Pools is pretty ambiguous on this topic. Here is what they tell you to do for a Forgot Password flow, and the link you may find it at:

cognitoUser.forgotPassword({
        onSuccess: function (result) {
            console.log('call result: ' + result);
        },
        onFailure: function(err) {
            alert(err);
        },
        inputVerificationCode() {
            var verificationCode = prompt('Please input verification code ' ,'');
            var newPassword = prompt('Enter new password ' ,'');
            cognitoUser.confirmPassword(verificationCode, newPassword, this);
        }
    });

http://docs.aws.amazon.com/cognito/latest/developerguide/using-amazon-cognito- user-identity-pools-javascript-examples.html

但是,当我将这段代码放到定义并登录了cognitoUser的项目中时,似乎什么也没有即将发生。我了解我需要以某种方式将此代码集成到向用户发送验证码,并要求他们输入新密码的方式,但找不到有关如何执行此操作的任何信息。有想法吗?

However when I drop this code into my project where a cognitoUser is defined and signed in, nothing seems to happen. I understand I need to somehow integrate this code with sending a verification code to the user, and asking them for a new password, but can't find anything on how to do this. Thoughts?

谢谢

推荐答案

使用忘记的密码流重置密码有两个步骤:

Resetting the password with forgot password flow has two steps:


  1. 通过向服务请求验证码来启动该过程。验证码将发送到用户的电话/电子邮件中。

  2. 使用提供的验证码设置新密码。

使用这两个功能执行上述步骤并重置密码:

Use these two functions to perform the above steps and reset the password:


  1. cognitoUser.forgotPassword() :这将启动忘记密码的流程。该服务生成验证码并将其发送给用户。通过callback.inputVerificationCode(data)返回的数据指示验证代码的发送位置。

  1. cognitoUser.forgotPassword(): This will start the forgot password process flow. The service generates a verification code and sends it to the user. The "data", returned through callback.inputVerificationCode(data), indicates where the verification code was sent.

cognitoUser.confirmPassword() :使用提供的验证码和此功能来设置新密码。

cognitoUser.confirmPassword(): Use the delivered verification code with this function to set a new password.

这篇关于如何允许我的用户在Cognito用户池上重设密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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