You are right that passwords should not be stored in plain text ( they must be hashed ) and, therefore, cannot be delivered to users who have forgotten the password.
Essentially, what you want is a way around your regular authentication scheme, and you should first know that such a mechanism is the back door of the application.
Very often, an assumption is made that only the desired user can access the emails sent to the email address registered in your application. It is on this basis that the "standard" password reset is based. Here I take on the following:
- A page with a forgotten password is requested, and the user is prompted to enter their registered email address in the form, which they then send
- The receiving code checks if the registered email address is indeed registered, and if it is:
- remove the existing reset password for this address from the corresponding store
- create and save a new reset password for this address
- send an email to a user who tells them that
- "someone" requested a reset password
- to click the link if they really want to reset
- ignore email if they did not request a reset
- reply to the form message with a page that says something like a line , if the registered address has been registered, and then a reset message is sent "
- If the sent address was not registered in the application, then do nothing, but reply to this message with a page that says something like a line , if the registered address was registered and then reset the message is sent "- the same as if the address was valid (this makes it difficult for someone to find the email addresses registered in the application).
- Then the user receives the forgotten password by e-mail and clicks on the link to it. The link delivers a reset token to the application.
- After receiving the reset password, the code checks if the token exists in the store and that it has not expired. If they are correct, then you assume that this must be a registered user who sent the token, and you can allow them to set a new password (a simple form with password and password entries and a submit button that contains zero personal information - even their name).
- Once the password is set, you can direct the user to the login page, where they enter their credentials, as usual.
This is not an ideal scheme. This is a compromise between security and convenience, and make no mistake that it is the back door of the application. For low value applications, it is usually good enough.
Further reading:
jah
source share