MCPcopy Create free account
hub / github.com/LionC/express-basic-auth / safeCompare

Function safeCompare

index.js:7–17  ·  view source on GitHub ↗
(userInput, secret)

Source from the content-addressed store, hash-verified

5// Credits for the actual algorithm go to github/@Bruce17
6// Thanks to github/@hraban for making me implement this
7function safeCompare(userInput, secret) {
8 const userInputLength = Buffer.byteLength(userInput)
9 const secretLength = Buffer.byteLength(secret)
10
11 const userInputBuffer = Buffer.alloc(userInputLength, 0, 'utf8')
12 userInputBuffer.write(userInput)
13 const secretBuffer = Buffer.alloc(userInputLength, 0, 'utf8')
14 secretBuffer.write(secret)
15
16 return !!(timingSafeEqual(userInputBuffer, secretBuffer) & userInputLength === secretLength)
17}
18
19function ensureFunction(option, defaultValue) {
20 if(option == undefined)

Callers 2

staticUsersAuthorizerFunction · 0.85
test.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…