Add function urandom_hex to passwordy.

This commit is contained in:
Ethan Dalool 2020-01-21 17:45:34 -08:00
parent 751ab5eaac
commit e6350f05d0

View file

@ -1,3 +1,5 @@
import math
import os
import string import string
import random import random
import sys import sys
@ -127,6 +129,11 @@ def make_sentence(length=None, joiner=' '):
result = joiner.join(words) result = joiner.join(words)
return result return result
def urandom_hex(length):
randbytes = os.urandom(math.ceil(length / 2))
token = ''.join('{:02x}'.format(x) for x in randbytes)
token = token[:length]
return token
if __name__ == '__main__': if __name__ == '__main__':
args = sys.argv[1:] args = sys.argv[1:]
argc = len(args) argc = len(args)