Simplify the password generator code
This commit is contained in:
parent
1278582f49
commit
e908241913
12
bin/genpw
12
bin/genpw
|
@ -6,16 +6,8 @@ Attributes:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import logging
|
|
||||||
import optparse
|
import optparse
|
||||||
|
import os
|
||||||
try:
|
|
||||||
import OpenSSL
|
|
||||||
except ImportError:
|
|
||||||
logging.error('Missing PyOpenSSL.')
|
|
||||||
logging.debug('Try `pip install pyopenssl`')
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
LENGTH = 16
|
LENGTH = 16
|
||||||
|
@ -27,7 +19,7 @@ def generate(length):
|
||||||
Args:
|
Args:
|
||||||
length (int): length of string to return
|
length (int): length of string to return
|
||||||
"""
|
"""
|
||||||
return base64.encodestring(OpenSSL.rand.bytes(256))[:length]
|
return base64.encodestring(os.urandom(256))[:length]
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Reference in a new issue