pcypher
v1.3.4
Published
A JS library that helps you encrypt password
Downloads
36
Maintainers
Readme
pcypher
A lightweight JS library that helps you encrypt password.
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
- 🐰 Alex
License
The MIT License (MIT)