You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import random
|
|
|
|
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 os
|
|
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':
|
|
import win32clipboard
|
|
win32clipboard.OpenClipboard()
|
|
win32clipboard.EmptyClipboard()
|
|
win32clipboard.SetClipboardText(pw, win32clipboard.CF_UNICODETEXT)
|
|
win32clipboard.CloseClipboard()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|