Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI command for generating hash #19

Closed
simonw opened this issue Feb 9, 2022 · 4 comments
Closed

CLI command for generating hash #19

simonw opened this issue Feb 9, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Feb 9, 2022

Safer alternative to /-/password-tool using this new plugin hook: https://docs.datasette.io/en/stable/plugin_hooks.html#register-commands-cli

@simonw simonw added the enhancement New feature or request label Feb 9, 2022
@simonw
Copy link
Owner Author

simonw commented Feb 9, 2022

Most basic implementation of this:

@hookimpl
def register_commands(cli):
    @cli.command(name="hash-password")
    @click.password_option()
    def _hash_password(password):
        "Return hash for provided password"
        click.echo(hash_password(password))

This runs like so:

% datasette hash-password
Password: 
Repeat for confirmation: 
Error: the two entered values do not match
Password: 
Repeat for confirmation: 
pbkdf2_sha256$260...

This works well as an interactive tool, but what about if people want to use it in a scripted way?

@simonw
Copy link
Owner Author

simonw commented Feb 9, 2022

For the scripted version, having an option for just reading the password a single time from stdin would be enough I think.

I want to avoid passing the password itself as a command-line argument because I don't want it accidentally ending up in bash history or /proc listings or similar.

@simonw
Copy link
Owner Author

simonw commented Feb 9, 2022

Maybe this:

echo 'my new password' | datasette hash-password --no-confirm

I think I need an "eager option" to implement this, in order to bypass the default @password_option() behaviour: https://click.palletsprojects.com/en/8.0.x/options/#callbacks-and-eager-options

@simonw simonw closed this as completed in dd79ca4 Feb 9, 2022
simonw added a commit that referenced this issue Feb 9, 2022
simonw added a commit that referenced this issue Jan 9, 2023
I forgot to check these tests in.
simonw added a commit that referenced this issue Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant