Skip to content

Commit 21b4c4b

Browse files
authored
Add comment about magic login code security (#2544)
1 parent a0dffb2 commit 21b4c4b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

pages/api/auth/[...nextauth].js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,9 @@ function generateRandomString (length = 6, charset = BECH32_CHARSET) {
408408
const bytes = randomBytes(length)
409409
let result = ''
410410

411-
// Map each byte to a character in the charset
411+
// Even though we're creating biased numbers by mapping each byte to a bech32 character,
412+
// this is still secure because it provides 30 bits of security (32^6 = 2^30)
413+
// and we are limiting the number of attempts.
412414
for (let i = 0; i < length; i++) {
413415
result += charset[bytes[i] % charset.length]
414416
}

0 commit comments

Comments
 (0)