password tool

This commit is contained in:
Wolfgang Hottgenroth 2023-02-07 11:42:19 +01:00
parent 5f68639955
commit ef877f0012
Signed by: wn
GPG Key ID: 836E9E1192A6B132
3 changed files with 38 additions and 0 deletions

1
tools/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.venv/

36
tools/genpw.py Executable file
View File

@ -0,0 +1,36 @@
from pbkdf2 import PBKDF2
from hashlib import sha512
from base64 import b64encode
import argparse
import secrets
import string
parser = argparse.ArgumentParser(description='genpw')
parser.add_argument('--length', '-l',
help='Length of auto-generated password',
required=False)
parser.add_argument('--password', '-p',
help='Password',
required=False)
args = parser.parse_args()
length = args.length
password = args.password
alphabet = string.ascii_letters + string.digits
iterations = 100000
if (not password):
if (not length):
raise Exception("Either length or password must be given")
password = ''.join(secrets.choice(alphabet) for i in range(int(length)))
salt = secrets.token_bytes(16)
hash = b64encode(PBKDF2(password, salt, iterations=iterations, digestmodule=sha512).read(64)).decode()
salt_b64 = b64encode(salt).decode()
print(f"{password=}")
print(f"PBKDF2$sha512${iterations}${salt_b64}${hash}")

1
tools/requirements.txt Normal file
View File

@ -0,0 +1 @@
pbkdf2==1.3