Rearrange and somewhat simplify passwordy main.
This commit is contained in:
parent
e6350f05d0
commit
b13f93c006
1 changed files with 64 additions and 49 deletions
|
@ -1,7 +1,7 @@
|
||||||
import math
|
import math
|
||||||
import os
|
import os
|
||||||
import string
|
|
||||||
import random
|
import random
|
||||||
|
import string
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
DEFAULT_LENGTH = 32
|
DEFAULT_LENGTH = 32
|
||||||
|
@ -134,18 +134,11 @@ def urandom_hex(length):
|
||||||
token = ''.join('{:02x}'.format(x) for x in randbytes)
|
token = ''.join('{:02x}'.format(x) for x in randbytes)
|
||||||
token = token[:length]
|
token = token[:length]
|
||||||
return token
|
return token
|
||||||
if __name__ == '__main__':
|
|
||||||
args = sys.argv[1:]
|
|
||||||
argc = len(args)
|
|
||||||
|
|
||||||
mode = listget(args, 0, 'password')
|
|
||||||
if 'help' in mode:
|
|
||||||
print(HELP_MESSAGE)
|
|
||||||
quit()
|
|
||||||
|
|
||||||
if 'sent' not in mode:
|
def main_password(argv):
|
||||||
length = listget(args, 0, str(DEFAULT_LENGTH))
|
length = listget(argv, 0, DEFAULT_LENGTH)
|
||||||
options = [a.lower() for a in args[1:]]
|
options = [a.lower() for a in argv[1:]]
|
||||||
|
|
||||||
if '-' in length:
|
if '-' in length:
|
||||||
length = length.replace(' ', '')
|
length = length.replace(' ', '')
|
||||||
|
@ -177,16 +170,38 @@ if __name__ == '__main__':
|
||||||
if 'nd' in options:
|
if 'nd' in options:
|
||||||
passtype += '+noduplicates'
|
passtype += '+noduplicates'
|
||||||
|
|
||||||
print(make_password(length, passtype=passtype))
|
return make_password(length, passtype=passtype)
|
||||||
|
|
||||||
else:
|
def main_sentence(argv):
|
||||||
length = listget(args, 1, str(DEFAULT_SENTENCE))
|
length = listget(argv, 1, DEFAULT_SENTENCE)
|
||||||
joiner = listget(args, 2, ' ')
|
joiner = listget(argv, 2, ' ')
|
||||||
|
|
||||||
if not length.isdigit():
|
try:
|
||||||
|
length = int(length)
|
||||||
|
except ValueError:
|
||||||
joiner = length
|
joiner = length
|
||||||
length = DEFAULT_SENTENCE
|
length = DEFAULT_SENTENCE
|
||||||
|
|
||||||
length = int(length)
|
return make_sentence(length, joiner)
|
||||||
|
|
||||||
print(make_sentence(length, joiner))
|
def main_urandom(argv):
|
||||||
|
length = listget(argv, 1, DEFAULT_LENGTH)
|
||||||
|
length = int(length)
|
||||||
|
return urandom_hex(length)
|
||||||
|
|
||||||
|
def main(argv):
|
||||||
|
mode = listget(argv, 0, 'password')
|
||||||
|
if 'help' in mode:
|
||||||
|
print(HELP_MESSAGE)
|
||||||
|
quit()
|
||||||
|
|
||||||
|
if 'sent' in mode:
|
||||||
|
print(main_sentence(argv))
|
||||||
|
elif 'urandom' in mode:
|
||||||
|
print(main_urandom(argv))
|
||||||
|
else:
|
||||||
|
print(main_password(argv))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
raise SystemExit(main(sys.argv[1:]))
|
||||||
|
|
Loading…
Reference in a new issue