How to create a random password? Create_user function

Possible duplicate:
Django Password Generator

d = Data.objects.get(key=key)    
User.objects.create_user(username = d.name, email= d.email, password =  password)

How to create an arbitrary password and send it by e-mail to user ( d.email)?

+5
source share
3 answers

django has make_random_passworda built-in random password generation method

my_password = User.objects.make_random_password()

it accepts parameters as lengthwell allowd_charsso that you can limit the length of the password and special characters and numbers

+25
source
def view_name(request):
    #make random password
    randompass = ''.join([choice('1234567890qwertyuiopasdfghjklzxcvbnm') for i in range(7)])

    #sending email
    message = "your message here"
    subject = "your subject here"
    send_mail(subject, message, from_email, ['to_email',])
0
source

:

Python

.

from django.core.mail import send_mail
password = rand_string
send_mail('Subject here', 'Here is the password: .'+password,
               'from@example.com', ['someone@gmail.com'],
               fail_silently=False)

EMAIL .py

EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'someone@gmail.com'
EMAIL_HOST_PASSWORD = 'mypassword'
-1

All Articles