Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation code for forgotten password before sending new one #4876

Open
Ownmarc opened this issue Feb 10, 2020 · 10 comments
Open

Validation code for forgotten password before sending new one #4876

Ownmarc opened this issue Feb 10, 2020 · 10 comments
Labels
Auth Related to Auth components/category Cognito Related to cognito issues feature-request Request a new feature need-product-input Needs non-technical requirements or direction to proceed Service Team Issues asked to the Service Team

Comments

@Ownmarc
Copy link

Ownmarc commented Feb 10, 2020

Summary

Would it be possible to validate the code of the forgotten password before having to send the new password ? Maybe its on Cognito's end ?

Motivation

I didn't find anyway of doing that with amplify. I would like to not show the new password fields if I can't validate the user's code for the forgotten password.

Actually there is 2 functions used in the request new password flow :

  • forgotPassword(username) that does its job and shouldn't be touched.
  • forgotPasswordSubmit(username, code, newPassword) that I suggest we could split in 2 steps (validate the code first and then allow for password reset instead of sending everything at the same time)

Basic Example

Being able to make a "forgotten password" flow in 3 steps :

  • Request code for forgotten password (send username)
  • Validate code (send username + code) => (get back a token or something)
  • Set the new password (send the token received at step 2 + username + new password )

Drawbacks

No, should have its own function along with forgotPasswordSubmit() and forgotPassword()

Related Issues

Here is all I found that is related :

amazon-archives/amazon-cognito-identity-js#466

References

None

@Ownmarc Ownmarc added the feature-request Request a new feature label Feb 10, 2020
@amhinson amhinson added the Auth Related to Auth components/category label Oct 20, 2020
@tnghia944
Copy link

.

@mlabieniec
Copy link
Contributor

Have you tried using Cognito Triggers? Specifically the CustomMessage_ForgotPassword trigger. This should allow you to retrieve the code/validate and trigger the UI update/s based on the response.

@Ownmarc
Copy link
Author

Ownmarc commented Jan 13, 2022

@mlabieniec I am not sure I understand how this allow us to validate the code the user is giving us. CustomMessage_ForgotPassword is used to template the email/message you will send to the user for forgotten password. You do not get access to the validation code there and even if you did, I do not see how one could use this trigger to do what was described in this issue. Would you mind elaborating ?

@nick-zh
Copy link

nick-zh commented Jan 17, 2022

I agree with @Ownmarc, i tried several triggers, i was unable to custom verify the code or get access to the code itself. This would be a very nice feature indeed.
I see two possible approaches:

  • be able to verify the code in an individual function (as suggested)
  • have a lambda trigger that allows you to customize the code that is being sent, so you have control over it

@ryan-hellowynd
Copy link

facing the same problem, is there any update on this issue?

@Zecento
Copy link

Zecento commented Nov 17, 2022

any updates?

@cwomack cwomack added Cognito Related to cognito issues Service Team Issues asked to the Service Team labels Feb 28, 2023
@tr3v3r
Copy link

tr3v3r commented Mar 1, 2023

As an hack solution it's possible to do something like.

const tempPassword = generateTempPassword()

await Auth.forgotPasswordSubmit(username, code, tempPassword)
// save temp password or pass to next screen
// on next screen / step just get saved temp password and ask user to add new one

await Auth.changePassword(username, tempPassword, newPassword)

@yunchanpaik
Copy link

As an hack solution it's possible to do something like.

const tempPassword = generateTempPassword()

await Auth.forgotPasswordSubmit(username, code, tempPassword)
// save temp password or pass to next screen
// on next screen / step just get saved temp password and ask user to add new one

await Auth.changePassword(username, tempPassword, newPassword)

This method doesn't work anymore since Auth.changePassword requires a cognito user instance instead of an username.

Would really love to get an official support from the AWS team on this issue. It's such a frustrating UX to enter the password two times only to find out the code had expired.

@dawid-bytys
Copy link

any update?

@cwomack cwomack changed the title RFC: 3 step flow for forgotten password ? Validation code for forgotten password before sending new one Jun 4, 2024
@cwomack cwomack added the need-product-input Needs non-technical requirements or direction to proceed label Jun 4, 2024
@dragosheroiu95
Copy link

dragosheroiu95 commented Jun 13, 2024

In our case we have some rules defined for the password (numbers, special chars, uppercase and lowercase letters) and I was able to achieve this by intentionally setting a failing password.

   try {
      await confirmResetPassword({
        username: email,
        confirmationCode: code,
        newPassword: "thiisafailingpassword", // a passworrd which will always fail since we have restrictions mentioned above
      });
    } catch (error) {
      if (error.name === "InvalidPasswordException") {
        // This means your code is a valid one
      } else {
        // Something is wrong with the code or any other error
        setErrorMessage(error.message);
      }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auth Related to Auth components/category Cognito Related to cognito issues feature-request Request a new feature need-product-input Needs non-technical requirements or direction to proceed Service Team Issues asked to the Service Team
Projects
None yet
Development

No branches or pull requests