Search code examples
djangopasswords

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?


Solution

  • You can also use the built in function make_random_password, but note that it is deprecated as of version 4.2:

    for user in new_users:
        password = User.objects.make_random_password()
        user.set_password(password)
        user.save(update_fields=['password'])
        # email/print password