To generate random password in Python
Ex:
import string
import random
from random import sample
def create_password(self):
"""
create a random password
"""
rand = string.ascii_letters + string.digits
length = 8
passwd = ''.join(sample(rand, length))
return passwd
Ex:
>>> import string
>>> import random
>>> from random import sample
>>> rand = string.ascii_letters + string.digits
>>> length = 8
>>> passwd = ''.join(sample(rand, length))
>>> passwd
'8fK6ZR0q'
>>>
Labels: generate password automatically, password, python
0 comments: Post Yours! Read Comment Policy ▼
PLEASE NOTE:
We have Zero Tolerance to Spam. Chessy Comments and Comments with Links will be deleted immediately upon our review.