password tool
This commit is contained in:
parent
5f68639955
commit
ef877f0012
1
tools/.gitignore
vendored
Normal file
1
tools/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.venv/
|
36
tools/genpw.py
Executable file
36
tools/genpw.py
Executable 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
1
tools/requirements.txt
Normal file
@ -0,0 +1 @@
|
||||
pbkdf2==1.3
|
Loading…
x
Reference in New Issue
Block a user