Add passwordy.random_hex in addition to urandom_hex.
This commit is contained in:
parent
cde65ca8f9
commit
c4dd1605a5
1 changed files with 9 additions and 1 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
'''
|
||||||
|
This module provides functions for generating random strings.
|
||||||
|
'''
|
||||||
import math
|
import math
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
@ -129,12 +132,17 @@ def make_sentence(length=None, joiner=' '):
|
||||||
result = joiner.join(words)
|
result = joiner.join(words)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def urandom_hex(length):
|
def random_hex(length):
|
||||||
randbytes = os.urandom(math.ceil(length / 2))
|
randbytes = os.urandom(math.ceil(length / 2))
|
||||||
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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
def main_password(argv):
|
def main_password(argv):
|
||||||
length = listget(argv, 0, DEFAULT_LENGTH)
|
length = listget(argv, 0, DEFAULT_LENGTH)
|
||||||
|
|
Loading…
Reference in a new issue