Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit 1bbba66

Browse files
authored
Make /admin/login return a descriptive error when no password is provided (#342)
1 parent 44c7b4e commit 1bbba66

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/account-db.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,13 @@ export function bootstrap(password) {
4949
}
5050

5151
export function login(password) {
52+
if (password === undefined || password === '') {
53+
return { error: 'invalid-password' };
54+
}
55+
5256
let accountDb = getAccountDb();
5357
let row = accountDb.first('SELECT * FROM auth');
58+
5459
let confirmed = row && bcrypt.compareSync(password, row.password);
5560

5661
if (confirmed) {
@@ -59,7 +64,7 @@ export function login(password) {
5964
// "session" that times out after a long time or something, and
6065
// maybe each device has a different token
6166
let row = accountDb.first('SELECT * FROM sessions');
62-
return row.token;
67+
return { token: row.token };
6368
} else {
6469
return null;
6570
}

src/app-account.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ app.post('/bootstrap', (req, res) => {
3838
});
3939

4040
app.post('/login', (req, res) => {
41-
let token = login(req.body.password);
41+
let { error, token } = login(req.body.password);
42+
43+
if (error) {
44+
res.status(400).send({ status: 'error', reason: error });
45+
return;
46+
}
47+
4248
res.send({ status: 'ok', data: { token } });
4349
});
4450

upcoming-release-notes/342.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
category: Bugfix
3+
authors: [matt-fidd]
4+
---
5+
6+
Make /admin/login return a descriptive error when no password is provided

0 commit comments

Comments
 (0)