dotfiles/bin/genpw

38 lines
655 B
Plaintext
Raw Normal View History

#!/usr/bin/env python
"""Module to generate a random string
Attributes:
LENGTH (int): Defaults to a length of 16
"""
import sys
import optparse
2019-01-04 12:15:02 +00:00
import os
import base64
LENGTH = 16
def generate(length):
"""Simple function to call OpenSSL
Args:
length (int): length of string to return
"""
2019-01-04 12:15:02 +00:00
return base64.encodestring(os.urandom(256))[:length]
def main():
"""Main function to call
"""
parser = optparse.OptionParser()
parser.add_option('-n', dest='length', default=LENGTH, type=int)
opts, _ = parser.parse_args()
print generate(opts.length)
if __name__ == '__main__':
main()
sys.exit(0)