Skip to content

Instantly share code, notes, and snippets.

@kdungs
Created August 18, 2012 19:51
Show Gist options
  • Save kdungs/3389341 to your computer and use it in GitHub Desktop.
Save kdungs/3389341 to your computer and use it in GitHub Desktop.
Random password generator.
#!/usr/bin/env python
import string as s
from random import randint
from sys import argv
CHARS = s.ascii_letters + s.digits + s.punctuation
def main(argc, argv):
l = 12
if argc > 1:
try:
l = int(argv[1])
except Exception:
print("Please enter an integer.")
exit(-1)
if l < 4:
print("Password should contain at least 4 digits.")
exit(-1)
pw = ""
for i in range(0, l):
pw += CHARS[randint(0, len(CHARS)-1)]
print(pw)
exit(0)
if __name__ == "__main__":
main(len(argv), argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment