Giter Site home page Giter Site logo

mrbontor / gen-secure-password Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 70 KB

Store secure password is a library to generate secure password using CryptoJs to make it safer when it stored to database.

License: MIT License

JavaScript 100.00%
cryptojs password-generator password-hasher better-password generate-secure-password store-secure-password

gen-secure-password's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.