Python - Generate Random Password Strings

Comments

Here are a few lines of Python code for when you need to generate random strings for things like passwords, hashes or the like.

import string
import random

# Just alphanumeric characters
chars = string.letters + string.digits

# Alphanumeric + special characters
chars = string.letters + string.digits + string.punctuation

pwdSize = 20

print ''.join((random.choice(chars)) for x in range(pwdSize))

Examples

Alphanumeric: liZgZkJGVoGe53lqpBsb
Special characters: g`hc8-%p’s>b6i[b`2P3

Next Post
Setup Virtual Domains in Postfix (Without a Database)

Previous Post
Bash - Generate Random Strings For Passwords


comments powered by Disqus