Skip to content

feat: add bcrypt cost parameter to hash-password #7149

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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

GreyXor
Copy link

@GreyXor GreyXor commented Jul 30, 2025

The caddy hash-password command allows users to generate hashed passwords for HTTP basic auth. It previously supported selecting the algorithm and plaintext, but did not expose the bcrypt cost parameter.

This change introduces a new --cost flag, allowing users to specify the bcrypt difficulty factor (cost), which controls the computational expense of the hash.

By default, the cost is kept at 14, consistent with the previous behavior if no custom value is provided.

Context: https://pkg.go.dev/golang.org/x/crypto/bcrypt#GenerateFromPassword

@CLAassistant
Copy link

CLAassistant commented Jul 30, 2025

CLA assistant check
All committers have signed the CLA.

@mohammed90
Copy link
Member

You shouldn't modify the interface to add support for passing the cost. That's a breaking change. The cost value can be a field in the bcrypt type.

@GreyXor
Copy link
Author

GreyXor commented Jul 30, 2025

You shouldn't modify the interface to add support for passing the cost. That's a breaking change. The cost value can be a field in the bcrypt type.

Thanks for your input @mohammed90! I moved cost out of the interface to put it directly into the BcryptHash structure. Does that work better for you?

type BcryptHash struct {
// cost is the bcrypt hashing difficulty factor (work factor).
// Higher values increase computation time and security.
cost int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Configurable parts of module should be exported. If there's assumption of default value, we usually implement those checks in Provision method, which I believe at this point it's needed.

Copy link
Author

@GreyXor GreyXor Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the Provision method called in the CLI context? Exported Provision doesn't seem to be invoked.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry 🤦🏼 I got confused with things. You're right, Provision is not called from the CLI to hash the password. It's also not needed in the comparison. You can revert that last commit 😅

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, reverted. Do you see anything else that I could improve @mohammed90 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants