argparser, make it possible to generate non-confusable passwords
This commit is contained in:
parent
bceaeeb2ca
commit
517fcca08a
22
pw.py
22
pw.py
@ -2,21 +2,25 @@
|
||||
|
||||
import random
|
||||
|
||||
def generate_pw(length):
|
||||
def generate_pw(length, no_confuse):
|
||||
import string
|
||||
charset = string.ascii_letters + string.digits + '+-_?!.:,;'
|
||||
if no_confuse:
|
||||
for c in '1Il0O':
|
||||
charset = charset.replace(c, '')
|
||||
return ''.join([random.choice(charset) for _ in range(length)])
|
||||
|
||||
def main():
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
length = int(sys.argv[1])
|
||||
else:
|
||||
length = 12
|
||||
pw = generate_pw(length)
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser(prog='Password Generator', description='Generate a random password')
|
||||
parser.add_argument('-n', '--no-confuse', action='store_true', help='do not use easily confusable characters (1Il0O)')
|
||||
parser.add_argument('length', nargs='?', type=int, default=20, help='length of the password')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
pw = generate_pw(args.length, args.no_confuse)
|
||||
print(pw)
|
||||
|
||||
if os.name == 'nt':
|
||||
|
Loading…
Reference in New Issue
Block a user