Skip to content

Commit 9f95cf9

Browse files
author
Maledong
authored
doc: Fix 'pbkdf2Sync' encoding problem (#1805)
Ref: #1796. Since the '/newUser' request is encoded by 'sha512', and your corresponding '/auth' must also use 'sha512' as the digest encoding as well.
1 parent 3f3d9d5 commit 9f95cf9

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

locale/en/docs/guides/simple-profiling.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ app.get('/auth', (req, res) => {
6363
return res.sendStatus(400);
6464
}
6565

66-
const hash = crypto.pbkdf2Sync(password, users[username].salt, 10000, 512);
66+
const { salt, hash } = users[username];
67+
const encryptHash = crypto.pbkdf2Sync(password, salt, 10000, 512, 'sha512');
6768

68-
if (users[username].hash.toString() === hash.toString()) {
69+
if (crypto.timingSafeEqual(hash, encryptHash)) {
6970
res.sendStatus(200);
7071
} else {
7172
res.sendStatus(401);

locale/ko/docs/guides/simple-profiling.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ app.get('/auth', (req, res) => {
114114
return res.sendStatus(400);
115115
}
116116
117-
const hash = crypto.pbkdf2Sync(password, users[username].salt, 10000, 512);
117+
const { salt, hash } = users[username];
118+
const encryptHash = crypto.pbkdf2Sync(password, salt, 10000, 512, 'sha512');
118119
119-
if (users[username].hash.toString() === hash.toString()) {
120+
if (crypto.timingSafeEqual(hash, encryptHash)) {
120121
res.sendStatus(200);
121122
} else {
122123
res.sendStatus(401);
@@ -136,9 +137,10 @@ app.get('/auth', (req, res) => {
136137
return res.sendStatus(400);
137138
}
138139

139-
const hash = crypto.pbkdf2Sync(password, users[username].salt, 10000, 512);
140+
const { salt, hash } = users[username];
141+
const encryptHash = crypto.pbkdf2Sync(password, salt, 10000, 512, 'sha512');
140142

141-
if (users[username].hash.toString() === hash.toString()) {
143+
if (crypto.timingSafeEqual(hash, encryptHash)) {
142144
res.sendStatus(200);
143145
} else {
144146
res.sendStatus(401);

locale/uk/docs/guides/simple-profiling.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ app.get('/auth', (req, res) => {
6363
return res.sendStatus(400);
6464
}
6565

66-
const hash = crypto.pbkdf2Sync(password, users[username].salt, 10000, 512);
66+
const { salt, hash } = users[username];
67+
const encryptHash = crypto.pbkdf2Sync(password, salt, 10000, 512, 'sha512');
6768

68-
if (users[username].hash.toString() === hash.toString()) {
69+
if (crypto.timingSafeEqual(hash, encryptHash)) {
6970
res.sendStatus(200);
7071
} else {
7172
res.sendStatus(401);

locale/zh-cn/docs/guides/simple-profiling.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,10 @@ app.get('/auth', (req, res) => {
5252
return res.sendStatus(400);
5353
}
5454

55-
const hash = crypto.pbkdf2Sync(password, users[username].salt, 10000, 512);
55+
const { salt, hash } = users[username];
56+
const encryptHash = crypto.pbkdf2Sync(password, salt, 10000, 512, 'sha512');
5657

57-
if (users[username].hash.toString() === hash.toString()) {
58+
if (crypto.timingSafeEqual(hash, encryptHash)) {
5859
res.sendStatus(200);
5960
} else {
6061
res.sendStatus(401);

0 commit comments

Comments
 (0)