Created
August 18, 2012 19:51
-
-
Save kdungs/3389341 to your computer and use it in GitHub Desktop.
Random password generator.
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/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