You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1020 B
39 lines
1020 B
#!/usr/bin/env python3 |
|
""" |
|
Utility to set the admin password for docker-web-ui. |
|
It writes a JSON file `auth.json` containing a PBKDF2-SHA256 password hash. |
|
|
|
Usage: python set_password.py |
|
Then enter the desired password when prompted. |
|
""" |
|
import getpass |
|
import json |
|
import os |
|
from werkzeug.security import generate_password_hash |
|
|
|
PROJECT_ROOT = os.path.dirname(__file__) |
|
AUTH_FILE = os.path.join(PROJECT_ROOT, 'auth.json') |
|
|
|
|
|
def main(): |
|
print('Create admin password for docker-web-ui') |
|
while True: |
|
pwd = getpass.getpass('Password: ') |
|
if not pwd: |
|
print('Empty password not allowed') |
|
continue |
|
pwd2 = getpass.getpass('Confirm: ') |
|
if pwd != pwd2: |
|
print('Passwords do not match, try again.') |
|
continue |
|
break |
|
|
|
ph = generate_password_hash(pwd) |
|
data = {'password_hash': ph} |
|
with open(AUTH_FILE, 'w') as f: |
|
json.dump(data, f) |
|
print(f'Wrote password hash to {AUTH_FILE}') |
|
|
|
|
|
if __name__ == '__main__': |
|
main()
|
|
|