From b8fd65d8561516a3a534233458ce2ccefd519d2c Mon Sep 17 00:00:00 2001 From: Vivek Santayana Date: Fri, 19 Aug 2022 15:29:27 +0100 Subject: [PATCH] Added command line password reset tool. --- ref-test/reset.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 ref-test/reset.py diff --git a/ref-test/reset.py b/ref-test/reset.py new file mode 100644 index 0000000..0e917a0 --- /dev/null +++ b/ref-test/reset.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +from main import app +from app.models import User + +from sqlalchemy.exc import SQLAlchemyError + +import sys +from getpass import getpass + +with app.app_context(): + try: + users = User.query.all() + except SQLAlchemyError as exception: + sys.exit('Database error:', exception) + print('') + print('This interface will allow you to override the password for an administrator account.') + print('To exit this interface, press Ctrl + C.') + print('') + while True: + username = input('Username: ') + user = None + for _user in users: + if _user.get_username() == username: + user = _user + break + if not user: + print(f'Error: User \'{username}\' does not exist.') + continue + else: break + while True: + email = input('Email address: ') + if not email == user.get_email(): + print(f'Error: Incorrect email address for user \'{username}\'.') + continue + else: break + print('') + print('Authenticated using username and email address.') + print('Update the password for the account below.') + print('') + while True: + password = getpass('Enter password: ') + if len(password) < 6 or len(password) > 20: + print(f'Error: Password must be between 6 and 20 characters long.') + reenter_password = getpass('Reenter password: ') + if not password == reenter_password: + print(f'Error: Entered passwords do not match.') + continue + else: break + success, message = user.update(password=password) + if not success: + sys.exit(message) + print('') + print(f'Success: Password for user \'{username}\' has been updated.') \ No newline at end of file