Skip to content

Instantly share code, notes, and snippets.

@guillaumepiot
Last active December 22, 2015 03:49
Show Gist options
  • Save guillaumepiot/6413288 to your computer and use it in GitHub Desktop.
Save guillaumepiot/6413288 to your computer and use it in GitHub Desktop.
PYTHON - Generate a random password
import string
from random import choice
def generate_random_password(length=8, chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", digits=string.digits, specials=u'!@$%&?'):
#raise Exception(string.letters)
password = u''.join([choice(unicode(digits)) for i in range(3)])
password += u''.join([choice(unicode(chars.lower())) for i in range(3)])
password += u''.join([choice(unicode(chars.upper())) for i in range(3)])
password += u''.join([choice(specials) for i in range(1)])
return password
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment