I'm trying to setup a CLI with Python using click. I need to limit the number of times a user is able to attempt to log in.
I've been trying to use the context to keep a counter of the login attempts but to no avail.
import click
def validate_password(ctx, param, password):
"""func to check password validity"""
@click.command()
@click.password_option(confirmation_prompt=False, callback=validate_password)
def log_admin(password):
click.echo("Successful authentication.")
The thing is, the callback can be used to check the validity of the password : if it's well formatted or matches against the proper hash.
But I can't manage to create a counter which would stop the user prompt when reaching a certain value. The callback for validation example shows this.
What can I do to ensure a user does not try to authenticate more than a certain amount of times?