https://github.com/commenthol/bcrypt-password-hash
hash password with bcrypt
https://github.com/commenthol/bcrypt-password-hash
Last synced: 14 days ago
JSON representation
hash password with bcrypt
- Host: GitHub
- URL: https://github.com/commenthol/bcrypt-password-hash
- Owner: commenthol
- License: unlicense
- Created: 2018-07-01T19:26:51.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-01T19:35:22.000Z (almost 8 years ago)
- Last Synced: 2025-09-06T14:45:51.417Z (10 months ago)
- Language: JavaScript
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bcrypt-password-hash
> hash password with bcrypt
[](https://www.npmjs.com/package/bcrypt-password-hash/)
Generation and validation of passwords using bcrypt hashes.
Uses same api as [pbkdf2-password-hash](https://www.npmjs.com/package/pbkdf2-password-hash).
Requires node >= v8.0.0
## TOC
* [Example](#example)
* [API](#api)
* [`hash(password, [salt], [opts])`](#hashpassword-salt-opts)
* [`compare(password, passwordHash)`](#comparepassword-passwordhash)
* [Installation](#installation)
* [Tests](#tests)
* [LICENSE](#license)
## Example
Generate new password hash
```js
const passwordHash = require('bcrypt-password-hash')
// generates random salt
passwordHash.hash('password')
.then((hash) => {
//> hash === 'bcrypt$2b$10$Y6MKD5ZI5gtkvBdYyqwr1.CrHA66ppM/9YNDvacUuqWZSVduKQcIq'
})
```
Generate password hash with different options
```js
passwordHash.hash('password', {saltRounds: 14})
.then((hash) => {
//> hash === 'bcrypt$2b$14$9zjobUQJ9LVswQrQJ7leKe6NnJKMc3ZouykkhZZ6uFa9ARMZVSUgy'
})
```
Validate password hash
```js
const hash = 'bcrypt$2b$14$9zjobUQJ9LVswQrQJ7leKe6NnJKMc3ZouykkhZZ6uFa9ARMZVSUgy'
passwordHash.compare('password', hash)
.then((isValid) => {
//> isValid === true
})
```
## API
### `hash(password, [salt], [opts])`
Generate a new password hash for password using [bcrypt][].
**Parameters**
| parameter | type | description |
| ---------------------- | ------ | -------------------------------- |
| `password` | String | |
| `[salt]` | String | _optional:_ salt |
| `[opts.saltRound=10]` | Number | _optional:_ number of iterations |
**Returns** `Promise`, hashed password in `bcrypt$$$` notation.
### `compare(password, passwordHash)`
validate password against passwordHash
**Parameters**
| parameter | type | description |
| -------------- | ------ | ------------------- |
| `password` | String | plain-text password |
| `passwordHash` | String | hashed password |
**Returns** `Promise`, true if hash matches password
## Installation
Requires [nodejs](http://nodejs.org/) >= v8.0.0
```sh
$ npm install --save bcrypt-password-hash
```
## Tests
```sh
$ npm test
```
## LICENSE
UNLICENSE
[bcrypt]: https://www.npmjs.com/package/bcrypt