Can someone walk me through what's happening in flask-security's password reset token? The code is here on github:
https://github.com/mattupstate/flask-security/blob/develop/flask_security/recoverable.py
(There may be other parts up a directory.)
My understanding of what's happening:
- In the route defined by forgot_password() user submits a form to reset password
- A "reset_password_token" is generated. This consists of the user's ID + an md5() of the user's current (stored-encrypted) password?
- A link is generated to a reset password address containing the token.
- This link is emailed to the address given by user.email
- When the user clicks that link, they go to a route (defined in views), which is reset_password(token). The token value is an argument to this route.
- The route evaluates whether the token is valid and not expired.
- If so, this route renders a form asking for a new password, ResetPasswordForm().
Is that correct?
Also:
- If above is correct, is it safe to make the token contain a new md5() of the current password? I know it should be unique and costly to reverse, but still?
- Where is the expiration date stored?
I'm most specifically confused by the generate_password_reset function
data = [str(user.id), md5(user.password)]
return _security.reset_serializer.dumps(data)
and the
get_token_status(token, 'reset', 'RESET_PASSWORD')
function inside reset_password_token_status(token)