Created
March 5, 2013 14:38
-
-
Save gatesphere/5090721 to your computer and use it in GitHub Desktop.
Random Password Generator in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# this script generates a random password of length 8, | |
# or whatever length is passed in on the command line | |
from string import ascii_letters, digits, punctuation | |
import sys, random | |
chars = ascii_letters + digits + punctuation | |
chars = chars.replace("\\", "") | |
if __name__ == "__main__": | |
n = 8 | |
if len(sys.argv) == 2: | |
n = int(sys.argv[1]) | |
pw = "".join(random.sample(chars, n)) | |
print pw | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment