gen-secure-password
v1.0.0
Published
generate secure password using CryptoJS
Downloads
14
Maintainers
Readme
gen-secure-password
gen-secure-password is a library to generate secure password using CryptoJS to make it safer when it stored to database.
Features
- Using hashing algorithm (pbkdf2Sync)
- Able to custom options for more secure password (depends on Device RAM)
- Each password has random iteration
- password is unreadable
- no required dependency as long you already installed
NodeJS
Compatibility
All version NodeJS (v0.9.3), pbkdf2Sync added since: v0.9.3
Install
npm install gen-secure-password
Usage
there is an example in folder example for more detail.
By default, this library will return secure password with default configuration.
Generate Secure Password
const GenSecurePassword = require('../libs');
const password = "ThisIsAGoodPasswordIn2023!";
const secPwd = GenSecurePassword.GenerateSecurePassword(password)
console.log(secPwd);
example output:
{
"hash": "967bdb3665fe6001ca4d2f8b5b2a799abad7c51476a86bb9b1a27c0ad6065494634591177a8d9f233f38354704bdfede27b10753ed6f26f0a95dcacdd9dee03b",
"salt": "qTM9m3QRVYQLFtpD2AjcHrEv0fGeA5Kex14NzWwYRdg=",
"iterations": 6593
}
Store the result to database, it allows you to store them separately. example in database will looks like:
"username": "mrbontor",
"infoAuth": {
"hash": "967bdb3665fe6001ca4d2f8b5b2a799abad7c51476a86bb9b1a27c0ad6065494634591177a8d9f233f38354704bdfede27b10753ed6f26f0a95dcacdd9dee03b",
"salt": "qTM9m3QRVYQLFtpD2AjcHrEv0fGeA5Kex14NzWwYRdg=",
"iterations": 6593
}
Noted: _when verifying password, we will need _ hash
, salt
and iterations
Verify Secured Password
const GenSecurePassword = require('../libs');
const password = {
hash: "967bdb3665fe6001ca4d2f8b5b2a799abad7c51476a86bb9b1a27c0ad6065494634591177a8d9f233f38354704bdfede27b10753ed6f26f0a95dcacdd9dee03b",
salt: "qTM9m3QRVYQLFtpD2AjcHrEv0fGeA5Kex14NzWwYRdg=",
iterations: 6593
};
const validatePwd = GenSecurePassword.VerifySecurePassword(secPwd, password);
console.log(validatePwd)
//return Boolean
Configuration
GenSecurePassword.GenerateSecurePassword(password, options)
This library allows you to make more secure password.
default option:
{
"minIteration": 5000, //minimun
"maxIteration": 50000, // there is no maximum value, but consider to use below 500k for better performance.
"saltLength": 32, // minimum is 16, and consider to use between range 16 - 128 for better performance
}
Description
minIteration and maxIteration
minIteration
andmaxIteration
are used to generateIterations number
. The iterations argument must be a number set as high as possible. The higher the number of iterations, the more secure the derived key will be, but will take a longer amount of time to complete. source: pbkdf2SyncsaltLength
saltLength
is number to generateBuffer
inByte
with type dataBuffer
. The salt should be as unique as possible. It is recommended that a salt is random and at least 16 bytes long. See NIST SP 800-132 for details. source: pbkdf2Sync
As i mention that we need salt
and iteration
when verifying the password,
the reason is
when converting random or pseudorandom byte sequences to UTF-8 strings, subsequences that do not represent valid code points may be replaced by the Unicode replacement character (U+FFFD). The byte representation of the resulting Unicode string may, therefore, not be equal to the byte sequence that the string was created from.
for more detail, please follow this link
https://nodejs.org/api/crypto.html#using-strings-as-inputs-to-cryptographic-apis
Tests
npm test
TO DO
let me know if you have suggestion(s).
Contributing
1. Fork it!
2. Create your feature branch: git checkout -b my-new-feature
3. Commit your changes: git commit -am 'Add some feature'
4. Push to the branch: git push origin my-new-feature
5. Submit a pull request :D
License
If my work helps you, please consider