Python for Entrepreneurs Transcripts
Chapter: Sending and receiving email
Lecture: Concept: Password resets
0:02 Now that you've seen password resets in action, let's review the fundamental data structure that was central to this whole process,
0:10 so here is our PasswordReset class, which maps to our PasswordReset table via the __tablename__, and you can see that our id was created
0:20 with the intention of making this not easy to guess, remember, that was one of our keys to a good reset process was that
0:27 it's not reset one, reset two, but it's a big hard to guess more or less randomly generated thing, so our default value for a lambda here does that.
0:38 we want to store the created_date and we just do that with the default value as well, but we need that created_date so that we can expire these
0:45 after certain amount of time, in our demo we choose one day. And then finally, we need to be able to use up the reset code,
0:53 so we have a used_date so we know when it was used, just to keep it simple as a boolean, we have a was_used,
0:59 our used ip address actually had two vales, in the beginning it was the ip address used to create the reset code,
1:05 and then in the end, we overwrote that value with the actual ip address used to apply that code to the account. Maybe I should have two separate fields
1:16 created_by_ip_address used_by_ip_address, it's up to you, how you want to store that.
1:23 And finally, this password reset needs to apply to a particular user, and we make that link by them providing their email address,
1:32 we can then look up the account, we don't let them log in but we do grab the id
1:35 and associate it here so if they actually own that address they can go to their email
1:39 which we sent this code to them, the id basically, in their email they click it, they come back and then they can set that code for that user.
1:48 Alright, that's it for password resets, there is kind of a lot of small little steps,
1:52 but you can grab the most of the code from GitHub and just adapt it to your purpose.