This commit is contained in:
Халимов Рустам
2026-03-10 22:00:45 +03:00
parent b4b4b8e0d3
commit be0c3812fc
12 changed files with 232 additions and 46 deletions

View File

@@ -46,22 +46,26 @@ router.post('/register', registerLimiter, async (req, res) => {
}
if (!username || !password) {
console.log('Registration failed: missing username or password');
res.status(400).json({ error: 'Username и пароль обязательны' });
return;
}
if (!/^[a-zA-Z0-9_]{3,20}$/.test(username)) {
console.log('Registration failed: invalid username format', username);
res.status(400).json({ error: 'Username: 3-20 символов, только латиница, цифры, _' });
return;
}
if (password.length < config.minPasswordLength) {
console.log('Registration failed: password too short');
res.status(400).json({ error: `Пароль должен быть не менее ${config.minPasswordLength} символов` });
return;
}
// Password must contain at least one letter and one digit
if (!/[a-zA-Zа-яА-Я]/.test(password) || !/\d/.test(password)) {
console.log('Registration failed: password missing letters or digits');
res.status(400).json({ error: 'Пароль должен содержать буквы и цифры' });
return;
}