dotfiles/bin/genpw

39 lines
727 B
Plaintext
Raw Normal View History

#!/usr/bin/env python
2021-12-11 18:22:49 +00:00
"""
Module to generate a random string
Attributes:
LENGTH (int): Defaults to a length of 16
"""
2021-12-11 18:22:49 +00:00
import argparse
import base64
2021-12-11 18:22:49 +00:00
import os
import sys
LENGTH = 16
2021-12-11 18:22:49 +00:00
def generate(length: int) -> str:
"""Simple function to call OpenSSL
Args:
length (int): length of string to return
"""
2021-12-11 18:22:49 +00:00
return base64.encodebytes(os.urandom(256)).decode()[:length]
2021-12-11 18:22:49 +00:00
if __name__ == '__main__':
2021-12-11 18:22:49 +00:00
def main() -> int:
"""Main function to call"""
parser = argparse.ArgumentParser()
parser.add_argument('-n', dest='length', default=LENGTH, type=int)
args = parser.parse_args()
2021-12-11 18:22:49 +00:00
sys.stdout.write(generate(args.length))
2021-12-11 18:22:49 +00:00
return 0
sys.exit(main())