bcrypt-gen
v1.3.0
Published
bcrypt-gen is a command-line tool designed to generate bcrypt hashes conveniently and securely. It provides an easy-to-use interface for hashing passwords directly from the terminal, ensuring enhanced security for your applications.
Readme
bcrypt-gen
bcrypt-gen is a command-line tool designed to generate bcrypt hashes conveniently and securely. It provides an easy-to-use interface for hashing passwords directly from the terminal, ensuring enhanced security for your applications.
Installation
To use bcrypt-gen, you can install it globally using npm or use it directly with npx.
Install Globally
npm install -g bcrypt-genUse with npx
You can directly use npx without the need for a global installation:
npx bcrypt-genRun Locally Without npx
If npx is not available or fails in your environment, clone the project, install dependencies, and run the CLI directly with Node.js:
npm install
node bcrypt-gen.jsYou can also run the local CLI through npm:
npm run bcrypt-gen -- -p --pwd "mypassword"When using npm run, pass CLI arguments after --. For example, verification mode must be run like this:
npm run bcrypt-gen -- -v --hash '$2b$10$JnIM0IXCTThg/oXZ6nJFi.8DakzRT9RgTOCPNJQzAMDVeWA3w2iZ6' --pwd "123"Without --, npm handles flags like -v itself and prints the npm version instead of running bcrypt-gen verification mode.
Use single quotes around bcrypt hashes in shell commands. Bcrypt hashes contain $, and shells expand $... inside double quotes.
If Node.js 24 shows a DEP0169 warning about url.parse(), update the dependencies:
npm installOlder installs using [email protected] load @mapbox/node-pre-gyp, which triggers this warning on newer Node.js versions.
Usage
After installing or using npx, you can simply run the following command to generate a bcrypt hash for a password:
bcrypt-genor with npx:
npx bcrypt-genExamples
Interactive Mode
When you run the command without arguments or with the -i flag, you will be prompted to enter the password for which you want to generate the hash:
$ npx bcrypt-gen
Enter the password to generate the hash: 123
Enter the number of salt rounds (or press Enter for default 10):
Generated hash: $2b$10$JnIM0IXCTThg/oXZ6nJFi.8DakzRT9RgTOCPNJQzAMDVeWA3w2iZ6Generate Hash with Default Salt Rounds
You can directly provide a password to hash with default salt rounds (10):
$ npx bcrypt-gen -p --pwd "mypassword"
Generated hash: $2b$10$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxGenerate Hash with Custom Salt Rounds
You can specify custom salt rounds for stronger hashing:
$ npx bcrypt-gen -c --pwd "mypassword" --rounds 12
Generated hash: $2b$12$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxVerify a Password Against a Hash
You can verify if a password matches a given hash:
$ npx bcrypt-gen -v --hash '$2b$10$JnIM0IXCTThg/oXZ6nJFi.8DakzRT9RgTOCPNJQzAMDVeWA3w2iZ6' --pwd "123"
✅ Success - Password matches the hash.Interactive Verification Mode
You can also verify a password interactively, without passing the hash as a shell argument:
$ npx bcrypt-gen -iv
Enter the bcrypt hash to verify: $2b$10$JnIM0IXCTThg/oXZ6nJFi.8DakzRT9RgTOCPNJQzAMDVeWA3w2iZ6
Enter the password to verify: 123
✅ Success - Password matches the hash.$ npx bcrypt-gen -h
Usage: bcrypt-gen [options]
Options:
--version Show version number [boolean]
-h, --help Show help [boolean]
-i, --interactive Interactive mode with questions for password
and rounds [boolean]
-v, --verify Verify if the password matches the given hash
[boolean]
--interactive-verify, --iv Interactive mode with questions for hash and
password verification [boolean]
-c, --custom Generate hash for the given password with
custom saltRounds [boolean]
-p, --password Generate hash for the given password with
default saltRounds (10) [boolean]
--hash Hash to verify (used with -v) [string]
--pwd Password to hash or verify [string]
--rounds Number of salt rounds (used with -c) [number]
-o, --only Print only the generated hash (no label/tips)
[boolean]
Examples:
bcrypt-gen -i Run in interactive mode
bcrypt-gen -iv Run in interactive verification mode
bcrypt-gen -v --hash '$2b$10$...' --pwd Verify if password matches hash
"mypassword"
bcrypt-gen -c --pwd "mypassword" --rounds 12 Generate hash with custom salt rounds
bcrypt-gen -p --pwd "mypassword" Generate hash with default salt rounds
(10)
Use single quotes around bcrypt hashes in shell commands.
Features
- Simple and intuitive CLI interface powered by yargs
- Comprehensive command-line options with long and short forms
- Generates bcrypt hashes securely
- Suitable for quick password hashing needs
- Ideal for developers needing to hash passwords on the fly
Author
Fabio Almeida - Github
License
This project is licensed under the ISC License - see the LICENSE file for details.
