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
|
import random
|
||||||
|
|
||||||
def generate_pw(length):
|
def generate_pw(length, no_confuse):
|
||||||
import string
|
import string
|
||||||
charset = string.ascii_letters + string.digits + '+-_?!.:,;'
|
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)])
|
return ''.join([random.choice(charset) for _ in range(length)])
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
import sys
|
|
||||||
import os
|
import os
|
||||||
import time
|
import argparse
|
||||||
|
|
||||||
if len(sys.argv) > 1:
|
parser = argparse.ArgumentParser(prog='Password Generator', description='Generate a random password')
|
||||||
length = int(sys.argv[1])
|
parser.add_argument('-n', '--no-confuse', action='store_true', help='do not use easily confusable characters (1Il0O)')
|
||||||
else:
|
parser.add_argument('length', nargs='?', type=int, default=20, help='length of the password')
|
||||||
length = 12
|
|
||||||
pw = generate_pw(length)
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
pw = generate_pw(args.length, args.no_confuse)
|
||||||
print(pw)
|
print(pw)
|
||||||
|
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
|
Loading…
Reference in New Issue
Block a user