MCPcopy
hub / github.com/dcodeIO/bcrypt.js / genSaltSync

Function genSaltSync

index.js:87–102  ·  view source on GitHub ↗
(rounds, seed_length)

Source from the content-addressed store, hash-verified

85 * @throws {Error} If a random fallback is required but not set
86 */
87export function genSaltSync(rounds, seed_length) {
88 rounds = rounds || GENSALT_DEFAULT_LOG2_ROUNDS;
89 if (typeof rounds !== "number")
90 throw Error(
91 "Illegal arguments: " + typeof rounds + ", " + typeof seed_length,
92 );
93 if (rounds < 4) rounds = 4;
94 else if (rounds > 31) rounds = 31;
95 var salt = [];
96 salt.push("$2b$");
97 if (rounds < 10) salt.push("0");
98 salt.push(rounds.toString());
99 salt.push("$");
100 salt.push(base64_encode(randomBytes(BCRYPT_SALT_LEN), BCRYPT_SALT_LEN)); // May throw
101 return salt.join("");
102}
103
104/**
105 * Asynchronously generates a salt.

Callers 2

_asyncFunction · 0.85
hashSyncFunction · 0.85

Calls 2

base64_encodeFunction · 0.85
randomBytesFunction · 0.85

Tested by

no test coverage detected