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 random password and send this via e-mail to user (d.email
) ?
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 random password and send this via e-mail to user (d.email
) ?
in django make_random_password
is a built in method for generating random password
my_password = User.objects.make_random_password()
it accepts parameters as length
and allowd_chars
with that you can limit the password length and special symbols and numbers
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',])
Use this to create random password:
Random string generation with upper case letters and digits in Python
And to send email.
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)
And you need to define some EMAIL settings in your settings.py
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = 'someone@gmail.com'
EMAIL_HOST_PASSWORD = 'mypassword'