Hello all users that doesn’t know how to hash passwords!
I’ve made a very convenient module made to hash and verify passwords, or other stuff. It supports ALL hashes that node (OpenSSL) supports. It uses a stragey called salt+hash
. It also supports using keys for the shake
hashes.
If you want to spectate the source code of the module you can go to https://ihacks.dev/ihack2712/ihacks-hash.
If you want to download the module on Glitch: pnpm install ihacks-hash
.
Here’s a quick guide:
const { hash, test } = require("ihacks-hash");
// Hash a password:
const hashed = hash("sha512", "my password");
// Verify that some text is the same hashed.
const isValid = test(hashed, "my password");
Version 2 Update!
I’ve made an update to the module that adds support for multiple hashing rounds!
Docs
hash(hash, text, key?, rounds?, salt?)
Hash some content into a string component.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
hash | HashName | No | None | The name of the hash you want to use. |
text | string | No | None | The text you want to hash. |
key | string | Yes | undefined |
Whether or not to use a key whilst hashing. Recommended. |
rounds | number | Yes | 1 |
How many rounds to hash some content. |
salt | string | Yes | undefined |
The salt to use when hashing, this is only here for my convenience, do not use. |
Returns: (string
) The hashes content.
test(data, text, key?)
Test if some text would be equal to some hashed content when hashed.
Parameter | Type | Optional | Default | Description |
---|---|---|---|---|
data | string | No | None | The hashed string component you want to test against. |
text | string | No | None | The unhashed text you want to test against the hash. |
key | string | Yes | undefined |
Whether or not to use a key whilst hashing. Recommended. |
Returns: (boolean
) Whether or not the text was the same as the data when hashed.
HashName
Type: string
HashName is an enumerable (type) of the list of supported hashing algorithms.
Example (basic hash & test)
// Import the module.
const { hash, test } = require("ihacks-hash");
// Information
const password = "MyVeryFakePassword123";
// Hash a password.
const hashed = hash("sha512", password);
const hashed2 = hash("sha512", password);
// Test the hash.
test(hashed, password); // true
hashed === hashed2; // false
Example (basic hash w/ key)
// Import the module.
const { hash, test } = require("ihacks-hash");
// Server Key
const key = "Super Secret Server Key";
// Information
const password = "MyVeryFakePassword123";
// Hash a password.
const hashed = hash("sha512", password, key);
const hashed2 = hash("sha512", password, key);
// Test the hash.
test(hashed, password, key); // true
hashed === hashed2; // false
Example (basic hash w/ multiple hashing rounds)
// Import the module.
const { hash, test } = require("ihacks-hash");
// How many rounds to hash.
const rounds = 1000; // Recommended value: 1000
// Server Key
const key = "Super Secret Server Key";
// Information
const password = "MyVeryFakePassword123";
// Hash a password.
const hashed = hash("sha512", password, key, rounds);
const hashed2 = hash("sha512", password, key, rounds);
// Test the hash.
test(hashed, password); // true
hashed === hashed2; // false
Example (basic hash w/ key & multiple hashing rounds)
// Import the module.
const { hash, test } = require("ihacks-hash");
// How many rounds to hash.
const rounds = 1000; // Recommended value: 1000
// Information
const password = "MyVeryFakePassword123";
// Hash a password.
const hashed = hash("sha512", password, null, rounds);
const hashed2 = hash("sha512", password, null, rounds);
// Test the hash.
test(hashed, password); // true
hashed === hashed2; // false