Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to allow users to change their own passwords in Django?

Tags:

python

django

Can any one point me to code where users can change their own passwords in Django?

like image 930
Hulk Avatar asked Dec 09 '09 13:12

Hulk


People also ask

How do I give permission to user in Django?

With Django, you can create groups to class users and assign permissions to each group so when creating users, you can just assign the user to a group and, in turn, the user has all the permissions from that group. To create a group, you need the Group model from django. contrib. auth.

What is the preferred method for customizing password length in Django?

class MinimumLengthValidator (min_length=8) Validates that the password is of a minimum length. The minimum length can be customized with the min_length parameter.

Does Django automatically hash passwords?

Passwords are hashed, by default, using the PBKDF2 algorithm. However, Django provides the option to use other algorithms such as Argon2 and bcrypt.


2 Answers

Django comes with a user authentication system. It handles user accounts, groups, permissions and cookie-based user sessions. This document explains how things work.

How to change Django passwords

See the Changing passwords section

  1. Navigation to your project where manage.py file lies

  2. $ python manage.py shell

  3. type below scripts :

 from django.contrib.auth.models import User u = User.objects.get(username__exact='john') u.set_password('new password') u.save() 

You can also use the simple manage.py command:

manage.py changepassword *username*

Just enter the new password twice.

from the Changing passwords section in the docs.


If you have the django.contrib.admin in your INSTALLED_APPS, you can visit: example.com/path-to-admin/password_change/ which will have a form to confirm your old password and enter the new password twice.

like image 146
Svetlozar Angelov Avatar answered Sep 24 '22 03:09

Svetlozar Angelov


You can also just use the django.contrib.auth.views.password_change view in your URLconf. It uses a default form and template; supplying your own is optional.

like image 33
Ben James Avatar answered Sep 25 '22 03:09

Ben James