README
sorthash
Encryption library
Current features
- Hash passwords, with salt
- Compare passwords
- Generate random strings composed of numbers or characters
Important to know
You need to store both the password and salt in order to compare later.
Usage of the password hash / compare functions
// Includes sorthash
const sorthash = require("sorthash");
// Hashes the password
var password = "Example123";
var saltLength = 20;
var { hash, salt } = sorthash.hash(password, saltLength); // Returns something like this: aabbbcchhwwxx11133455
// Compares the password
if (sorthash.compare(password, salt, hash)) {
// -> The passwords match
} else {
// -> The passwords don't match
}
Usage of the randomstring generator
// Includes sorthash
const sorthash = require("sorthash");
// Generates random chars, the length must be between 1 and 500
var chars = sorthash.randomString({
type: "chars",
length: 20
});
// Generates random numbers
var chars = sorthash.randomString({
type: "numbers",
length: 20
});