Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Password Generator

I have imported a heap of users and their data to a django project. I need to assign a password to each. Is the such a snippet out there for password generation that will cope with the Django hash and salt?

like image 297
Timbadu Avatar asked Feb 28 '12 10:02

Timbadu


People also ask

Is there any password field in Django?

Django provides a flexible password storage system and uses PBKDF2 by default.

Can we decrypt Django password?

@anotheruser Yes, you can't 'decrypt' a hashed password through django. (A hash is a one-way function not really encryption). You could possibly save the password of the user in plaintext in the DB, when they create a user account.


2 Answers

You can also use the built in function make_random_password

for user in new_users:     password = User.objects.make_random_password()     user.set_password(password)     user.save(update_fields=['password'])     # email/print password 
like image 54
JamesO Avatar answered Oct 02 '22 18:10

JamesO


Also you can use from django.utils.crypto import get_random_string out of auth module, it accepts keyword arguments length and allowed_chars as well.

like image 37
mitnk Avatar answered Oct 02 '22 19:10

mitnk