Password Reset in Django – Complete Guide
🔐 Introduction
Web applications lo Password Reset feature chala important.
User password marchipothe, easy ga recover chesukovadaniki use avutundi.
Real-time lo:
- Gmail
anni password reset system use chestayi.
⚙️ How Password Reset Works?
👉 Step-by-step flow:
- User “Forgot Password” click chestadu
- Email enter chestadu
- System reset link send chestundi
- User link open chestadu
- New password set chestadu
👉 Idi secure ga untundi because:
- Token based verification
- Time limit untundi
⚙️ Django Password Reset Code
1️⃣ settings.py (EMAIL Setup)
# settings.py
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
👉 Dev lo console lo email link chupistundi
👉 Production lo Gmail SMTP use cheyachu
2️⃣ urls.py
from django.urls import path
from django.contrib.auth import views as auth_views
urlpatterns = [
path('password-reset/',
auth_views.PasswordResetView.as_view(
template_name='registration/password_reset.html'
),
name='password_reset'),
path('password-reset/done/',
auth_views.PasswordResetDoneView.as_view(
template_name='registration/password_reset_done.html'
),
name='password_reset_done'),
path('reset/<uidb64>/<token>/',
auth_views.PasswordResetConfirmView.as_view(
template_name='registration/password_reset_confirm.html'
),
name='password_reset_confirm'),
path('reset/done/',
auth_views.PasswordResetCompleteView.as_view(
template_name='registration/password_reset_complete.html'
),
name='password_reset_complete'),
]
🎨 Templates
📄 password_reset.html
<h2>Forgot Password</h2>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Send Reset Link</button>
</form>
📄 password_reset_done.html
<h2>Email Sent</h2>
<p>Check your email for reset link 📩</p>
📄 password_reset_confirm.html
<h2>Set New Password</h2>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Change Password</button>
</form>
📄 password_reset_complete.html
<h2>Password Changed Successfully 🎉</h2>
<a href="{% url 'login' %}">Login</a>
🔗 Add Link in Login Page
<a href="{% url 'password_reset' %}">Forgot Password?</a>
🧠 Explanation (Simple)
👉 Django automatically:
- Token generate chestundi
- Email send chestundi
- Password update handle chestundi
👉 Manam:
- URLs configure chestam
- Templates create chestam
🔥 Final Flow
👉 User clicks Forgot Password
👉 Email link vastundi
👉 Link open chesi password change chestadu
it is good and best content i never ever seen
ReplyDelete