Add function urandom_hex to passwordy.
This commit is contained in:
parent
751ab5eaac
commit
e6350f05d0
1 changed files with 7 additions and 0 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue