fix: prevent username/email enumeration via registration error messages

This commit is contained in:
2026-07-13 18:29:32 +08:00
parent b24f8cd74d
commit befd51dbd5
2 changed files with 4 additions and 7 deletions

View File

@@ -24,8 +24,8 @@ router.post('/auth/register', async (req, res) => {
const { username, password, email, game_name, game_uid } = req.body;
if (!username || !password || !email || !game_name || !game_uid) return res.status(400).json({ error: '所有字段必填' });
if (password.length < 6) return res.status(400).json({ error: '密码至少6位' });
if (await getRow('SELECT id FROM users WHERE username = ?', [username])) return res.status(400).json({ error: '用户名已存在' });
if (await getRow('SELECT id FROM users WHERE email = ?', [email])) return res.status(400).json({ error: '邮箱已注册' });
if (await getRow('SELECT id FROM users WHERE username = ?', [username])) return res.status(400).json({ error: '注册失败,请检查输入信息' });
if (await getRow('SELECT id FROM users WHERE email = ?', [email])) return res.status(400).json({ error: '注册失败,请检查输入信息' });
const hashed = bcrypt.hashSync(password, 10);
const verifyToken = uuid();