Skip to content

Instantly share code, notes, and snippets.

@johngian
Last active August 29, 2015 13:56
Show Gist options
  • Save johngian/9005563 to your computer and use it in GitHub Desktop.
Save johngian/9005563 to your computer and use it in GitHub Desktop.
Password generator from regular expression.
# Dependencies: pip install exrex
# Run: python ./regexpassgen.py --output <filename> <regex>
import argparse
import exrex
if __name__=='__main__':
parser = argparse.ArgumentParser()
parser.add_argument('regex', type=str, help='Password generator regex.')
parser.add_argument('-o', '--output', action='store', help='Output file.')
args = parser.parse_args()
passwords = exrex.generate(args.regex)
try:
f = open(args.output, 'w')
try:
for p in passwords:
f.write(p)
f.write('\n')
finally:
f.close()
except IOError:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment