-2

I'm new to Python-Flask. My problem is I'm not sure how to reset the password. Can anyone give the sample code or suggest an idea.

Here is orm.py

class Enduser(Base):
   __tablename__='enduser'
   name=Column(String(50))
   email=Column((String(50))
   password=Column(String(50))
Sean Breckenridge
  • 1,932
  • 16
  • 26
Falcon bliss
  • 71
  • 2
  • 11

1 Answers1

1

Alright, so to give you a brief idea, here is how a password reset should work :

-You need another table (password_reset)

The table must have a unique code for the password reset link and a foreign key to your user table.

-Endpoint for user to actually reset the password

The endpoint will receive the unique code which is in the password_reset table

The flow :

  1. User requested for password reset with his/her email.
  2. Insert a row on the password_reset table, generate the unique code randomly.
  3. Send the link to password reset endpoint with the unique code via email or something.
  4. Ask user for new password on the page and change it on your User model.
  5. Delete the password_reset row.

Hope it helps

Gabriel B.R
  • 278
  • 1
  • 7
  • ...If you don't mind can you practical example like example demo code. – Falcon bliss Feb 26 '18 at 10:26
  • You don't need a second table really-- just use a library like `itsdangerous` to encrypt/serialize the user identifier and a timestamp and use that as the password reset token-- much easier workflow. See my answer https://stackoverflow.com/questions/14713757/what-is-the-best-way-to-generate-a-reset-token-in-python/14717974#14717974 – Doobeh Feb 26 '18 at 12:53
  • @Doobeh I haven't thought about using cryptographic functions. But still I think this answer is easier to understand and you actually know what you did (even beginners) – Gabriel B.R Feb 26 '18 at 13:07
  • i am not sure about reset password library.could you give example for how to give the url and generate random numbers.can you give step by step sample demo.i am unable to understand the your posted link. – Falcon bliss Feb 26 '18 at 15:02