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

Function safeStringCompare

index.js:211–217  ·  view source on GitHub ↗

* Compares two strings of the same length in constant time. * @param {string} known Must be of the correct length * @param {string} unknown Must be the same length as `known` * @returns {boolean} * @inner

(known, unknown)

Source from the content-addressed store, hash-verified

209 * @inner
210 */
211function safeStringCompare(known, unknown) {
212 var diff = known.length ^ unknown.length;
213 for (var i = 0; i < known.length; ++i) {
214 diff |= known.charCodeAt(i) ^ unknown.charCodeAt(i);
215 }
216 return diff === 0;
217}
218
219/**
220 * Synchronously tests a password against a hash.

Callers 2

compareSyncFunction · 0.85
_asyncFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected