From e6350f05d03fd364239d9b3aa95af9faefdcd686 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 21 Jan 2020 17:45:34 -0800 Subject: [PATCH] Add function urandom_hex to passwordy. --- voussoirkit/passwordy.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/voussoirkit/passwordy.py b/voussoirkit/passwordy.py index 76ac9ad..51547a7 100644 --- a/voussoirkit/passwordy.py +++ b/voussoirkit/passwordy.py @@ -1,3 +1,5 @@ +import math +import os import string import random import sys @@ -127,6 +129,11 @@ def make_sentence(length=None, joiner=' '): result = joiner.join(words) 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__': args = sys.argv[1:] argc = len(args)