Created
April 30, 2018 19:36
-
-
Save WardsParadox/3f092670edb05902284f7ad6d26f25ec to your computer and use it in GitHub Desktop.
PassGen for student passwords
This file contains hidden or 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 | |
''' | |
Generates password of random 4-letter word + 4-digit number | |
''' | |
from random import randint, \ | |
choice | |
import os | |
import argparse | |
import re | |
def randomwithndigits(length): | |
''' | |
random digit of length n | |
''' | |
range_start = 10**(length-1) | |
range_end = (10**length)-1 | |
return randint(range_start, range_end) | |
def passgen(numberofchoices, lengthofword): | |
''' | |
Loop to print number of choices | |
''' | |
WORDFILE = open(os.path.abspath("/usr/share/dict/words")).read() | |
WORDLIST = list(re.findall(r'\b\w{%s}\b' % lengthofword, WORDFILE)) | |
count = 0 | |
while count < numberofchoices: | |
print "{0}{1}".format(choice(WORDLIST).lower(), randomwithndigits(4)) | |
count += 1 | |
def main(): | |
''' | |
Main Functions | |
''' | |
parser = argparse.ArgumentParser(description='Generates Student Passwords') | |
parser.add_argument('-c', '--count', type=int, | |
help='Generates passwords this many times', default=1) | |
parser.add_argument('-l', '--length', type=int, | |
help="Length of word to be used", default=4) | |
args = parser.parse_args() | |
passgen(args.count, args.length) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment