2.0.0 • Published 4 years ago

ihacks-hash v2.0.0

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

An idiot's guide to good hashing

Download the hashing module.

yarn add ihacks-hash
npm i -S ihacks-hash
pnpm install ihacks-hash

Docs

hash(hash, text, key?, rounds?, salt?)

Hash some content into a string component.

Parameter Type OptionalDefault Description
hashHashNameNoNone The name of the hash you want to use.
text stringNoNoneThe text you want to hash.
keystringYesundefined Whether or not to use a key whilst hashing. Recommended.
 roundsnumberYes 1How many rounds to hash some content.
salt stringYes 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.

ParameterTypeOptionalDefaultDescription
datastring NoNone   The hashed string component you want to test against.
textstring NoNone The unhashed text you want to test against the hash.
keystringYes  undefinedWhether 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 = 32; // Recommended value: 32

// 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 = 32; // Recommended value: 32

// 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
2.0.0

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago