Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion contest.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"endTime": "2019-02-27T17:30:00.000Z",
"mode": "OI",
"probList": ["LARES", "GCD"],
"allowedCodeExt": [".C", ".CPP"]
"allowedCodeExt": [".C", ".CPP"],
"passwordRegex": ".{6,18}"
}
2 changes: 2 additions & 0 deletions src/controller/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const bcrypt = require("bcryptjs");
const { join } = require("path");
const cwd = require("../config/cwd");
const { passwordRegex } = require("../config/contest");
const Datastore = require("nedb");
const { isUsername, isPassword } = require("../util/userValid");

Expand Down Expand Up @@ -185,6 +186,7 @@ async function updateUserName(user_id, old_name, new_name) {
*/
async function updateUserPassword(user_id, old_pass, new_pass) {
if (!isPassword(new_pass)) throw new Error("Invalid new password");
if (!new_pass.match(passwordRegex)) throw new Error("Password does not match requirements");
const newHashPass = bcrypt.hash(new_pass, bcrypt.genSaltSync(10));

const dbUserPassHash = await readUserPassHash(user_id);
Expand Down
9 changes: 7 additions & 2 deletions src/util/config/contestConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ function parseCtCfg(configData) {
endTime,
mode,
probList,
allowedCodeExt
allowedCodeExt,
passwordRegex: pregex
} = configData;

name = String(name);
Expand All @@ -50,6 +51,9 @@ function parseCtCfg(configData) {
startTime = parseTime(startTime);
endTime = parseTime(endTime);

if (pregex && (typeof pregex !== 'string'))
throw new TypeError(`passwordRegex must be a string, got ${typeof pregex}`);

if (startTime >= endTime) throw new Error("Start time is after end time");

return {
Expand All @@ -58,7 +62,8 @@ function parseCtCfg(configData) {
startTime: startTime,
endTime: endTime,
probList: parseContainer(probList),
allowedCodeExt: parseContainer(allowedCodeExt)
allowedCodeExt: parseContainer(allowedCodeExt),
passwordRegex: new RegExp(pregex ? pregex : '.{6,18}')
};
}

Expand Down