Home > Mobile >  How to securely generate random passwords in Django?
How to securely generate random passwords in Django?

Time:03-09

I have imported a set of user data into a Django project. Now I need to set a random password for each of them.

My question here is, how do I securely generate random passwords in Django?

CodePudding user response:

The django.utils.crypto.get_random_string() function returns a securely generated random string; those are suitable for passwords.

However, if you're using Django's auth system and planning on creating passwords that can't be used (e.g. that the users need to use your site's password recovery function to set their own password and log in), you can set the user's raw password to something starting with an exclamation mark'!'.

  • Related