npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gen-secure-password

v1.0.0

Published

generate secure password using CryptoJS

Downloads

14

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 and maxIteration are used to generate Iterations 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: pbkdf2Sync

  • saltLength

    saltLength is number to generate Buffer in Byte with type data Buffer. 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

MIT Licence

If my work helps you, please consider buying me a coffee


Back to top