https://github.com/kdcio/password
Generate password hash and salt
https://github.com/kdcio/password
digest hash kdc kdcio password salt
Last synced: about 1 year ago
JSON representation
Generate password hash and salt
- Host: GitHub
- URL: https://github.com/kdcio/password
- Owner: kdcio
- License: mit
- Created: 2020-05-18T10:45:56.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2025-05-12T08:25:05.000Z (about 1 year ago)
- Last Synced: 2025-05-12T09:53:49.626Z (about 1 year ago)
- Topics: digest, hash, kdc, kdcio, password, salt
- Language: JavaScript
- Homepage:
- Size: 916 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Password Hash and Salt Generator
This package will generate hash and salt given a password. It also has a function to validate a password input.
[](https://www.npmjs.com/package/@kdcio/password) [](https://bundlephobia.com/result?p=@kdcio/password) [](https://github.com/kdcio/password/actions?query=workflow%3Abuild) [](https://snyk.io/test/github/kdcio/password?targetFile=package.json) [](https://sonarcloud.io/dashboard?id=kdcio_password) [](https://sonarcloud.io/dashboard?id=kdcio_password) [](https://sonarcloud.io/dashboard?id=kdcio_password) [](https://github.com/kdcio/password/blob/master/LICENSE)
## Install
```terminal
npm i @kdcio/password
```
## Usage
### On user registration
```javascript
const { getHashSalt } = require('@kdcio/password');
const register = (password) => {
...
const {hash, salt} = getHashSalt(password);
...
};
```
Store the hash and salt in your database.
### On user login
```javascript
const { isValidPassword } = require('@kdcio/password');
const login = (username, password) => {
...
const {hash, salt} = getFromDatabase(username);
if(isValidPassword(password, hash, salt)) {
console.log("Password is correct");
} else {
console.log("Password is wrong");
}
...
};
```
## Configuration
Iterations, keylen and digest can be configured by defining environment variables.
- PW_ITERATIONS
- PW_KEYLEN
- PW_DIGEST
See algorithms in [NodeJs crypto](https://nodejs.org/api/crypto.html#crypto_crypto_createhmac_algorithm_key_options) docs for possible values for digest. More info on the link below.
## Reference
[https://nodejs.org/api/crypto.html#crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback](https://nodejs.org/api/crypto.html#crypto_crypto_pbkdf2_password_salt_iterations_keylen_digest_callback)