1.3.4 • Published 4 years ago

pcypher v1.3.4

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

pcypher

A lightweight JS library that helps you encrypt password.

NPM

Github issues Build Status: Linux npm license

Install via NPM

npm install pcypher

Usage

Required to Create an Environment Variable

Create a .env file in the root directory of your project. Add environment-specific variables on new lines in the form of NAME=VALUE. For example:

# environment sample content

SECRET_KEY=InputRandomKeyHere
KEY_LENGTH=16

To hash a password

const { hasher } = require('pcypher');

(async() => {
    try {
        const plainTextPassword = 'A password to hash';
        // returns a hash password
        const password = await hasher(plainTextPassword);
        console.log(password); //e8d3......3e60
    } catch (error) {
        console.error(error);
    }
})();

To check a password

const { comparePassword } = require('pcypher');

(async() => {
    try {
        //password from request body
        const plainTextPassword = req.body.password;
        //return boolean true or false
        const comparison = await comparePassword(plainTextPassword, hashedPassword);
        //hashedPassword: a password loaded from database
    } catch (error) {
        console.error(error);
    }
})();

Work also as a Promise

const { comparePassword } = require('pcypher');

const plainTextPassword = 'A password to hash';
const password = hasher(plainTextPassword);
    
password
    .then(result => {
        console.log(result) // e8d3......3e60
    })

Token Generator

Generate a token when someone requests for a password reset.

const { generateToken } = require('pcypher');

app.post('/password-reset', function(req, res, next) {
    const token = await generateToken();
    console.log(token); // e8d3......3e60
    
    //...some code

});

Contribute

We are at the very early stage of this repository. Any help and contribution is welcome.

  • Please Feel free to submit pull request.

Authors

License

The MIT License (MIT)

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.9

4 years ago

1.2.8

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago