from flask_httpauth import HTTPBasicAuth from werkzeug.security import check_password_hash from flask import current_app as app # Using the current Flask app context auth = HTTPBasicAuth() # Initialize the users dictionary once users = {} @auth.verify_password def verify_password(username, password): global users # Ensure we're modifying the global users dictionary if not users: # Only populate the dictionary if it's empty users = { "anon": app.config['USER_PASS_HASH'] } if username in users and check_password_hash(users.get(username), password): return username