Forgot Password in Django using Email | Django Reset Password Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone in this video I will show you  how you can Implement forgot password or reset   password feature in your Django project like when  the user click on the forgot password button we   will send some token or some link to the user  email or phone number and user need to pass   that token or user need to click on that link  and to change his password I will be using the   Django rest and Django rest password reset package  for implementing the feature of forget password   for sending email I will be using the send grid  so I am on the official website of sendgrid I   have a separate video on sandgrid like how you  can send emails through send it I will just give   you a brief overview about it first of all you  need to create your free accountants and grid   after creating this is the dashboard of my sanket  account after creating your free account you need   to authenticate the those senders or you  need to authenticate your domain you need   to click on verify a single sender and you need to  authenticate a sender that will send in the emails   I have already verified some senders   after that you need to create a new API key  so these are the apis keys that I have already   used for some of my projects so this is the  API key that I will be using in this project   after performing all these steps send grid  is ready to send image to your SBN emails   so I will be following the official website  the future documentation of this package   first of all you need to install Django rest  password reset in your project as you can   see I have already installed this package in  my project so I will I will not install this after installing after installing the Django test  a password reset you need to you need to copy and   the Django rest password reset and paste in  user installed apps in the settings.py file this is my settings.poi file and I need to paste in my the Django rest  password reset in my installed apps   after doing this step I need to run the  migrate command so this package contains   some tables that it will automatically  create when I run the migrate command let's open my database so these are the all the tables and that  and that I am will be using for this project   and this is a table that the Django  password reset pack is create so after doing this I need to register the URL  in the root URL patterns I need to copy this line and go to the urls.py in my main file that is  my root urls and I need to paste it in here   like when I hit the API slash API by the  localhost slash API slash password reset   it will it will ask me to enter my email when  I enter my email if the email is valid it will   send with the token to that email after that  I need to I need to hit the confirm password   endpoint and I need to paste my token and new  password here I will show you how I could do this   after doing this step I need to  implement the signal to sending the email in my user model I have registered the signalet so this is the   signal that with the name of  password reset token created I need to import these packages this is a  function that will be doing all the things   like it is a it is taking the password reset  token as an argument creating an email body   with the text light and this is a  token you need to pass this token   and this is the send grid and this is the code  for sending emails to send it I need to pass   the from email that is present in my environment  variables file the to email that the user pass   that I am will be getting that I will be getting  from and the reset a password object the subject   of the email and the content of the email it  can be plain text or it can be HTML content   after that I need to call the sendgrate  API client that I imported from sendgrid and then I need to send the email with the message  if the response is 200 and 202 it's mean the   message successfully sent and I will be printing  that the password is at image successfully sent   to my email if there is some added it will  display that failed to send in the email   let's run the server for this project  by writing python manage.py run server as you can see the server is running  over Port 8000 without any added so this is the root of my and  this is the root of my project   I need to hit the slash user slash login for  login the user this is the user already present   in my database I need to copy this user and  paste it here so uh note that the password   of user is one two three four five six seven  eight when I click on post as you can see it   is giving me the access token and refresh token  with the message that user is successfully uh is   a successful login so let's suppose I forgot  the password of this user I need to go to the this uh this endpoint that is the  localhost slash API slash password reset   when I hit this end point it will show me  that the request should be the post request   I need to pass my email so this is the email  already present in my database let's suppose   I paste some wrong email here it will show  me that the email is not present in database let's pass the correct email and  I need to click this post button   If the message is okay it's mean the email  is successfully sent to the respect email so this is the email that I just received you  can see your zero minutes ago and this is a   token that the password reset Library sent to  me it will expire after uh 60 minutes you can   set this expiry date by setting the variable  into settings.py file I need to copy this token   and I need to go to a slash API slash  password research select confirm so it is asking me to paste my token and paste  my new password like I am setting a new password for example IPS the wrong token here it  will show me that the token is not found   so I need to pass the correct  token I am resetting my password so the password should be node common  and it should not be entirely nomatic so   let's try some complex password let's  paste the token and try a password and hit post if the status is okay it's  mean the password is successfully set if I copy my user again  and paste it in Json format   and click on the post it will show me that  the email or password is invalid so I need   to pass my new password Here that I  just set as programmer one two three [Music] so as you can see the user is successfully  login and it will also provide me access   and the refresh token so in this  way you can implement the forgot   password or reset password feature in  your Django project thanks for watching
Info
Channel: Coding with Kazim
Views: 5,541
Rating: undefined out of 5
Keywords: reset password, forgot password django rest framework, django tutorial, how to send email using sendgrid, django reset password with email
Id: whK97tOV2z4
Channel Id: undefined
Length: 9min 49sec (589 seconds)
Published: Fri Jun 23 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.