update pass

This commit is contained in:
2026-09-30 10:09:08 +07:00
parent 3201a18fd4
commit dff0d32912
4 changed files with 26 additions and 24 deletions

View File

@@ -3619,8 +3619,8 @@ async function createTables() {
try {
const initialAdminPassword = String(process.env.INITIAL_ADMIN_PASSWORD || '');
if (initialAdminPassword) {
if (initialAdminPassword.length < 12) {
throw new Error('INITIAL_ADMIN_PASSWORD must contain at least 12 characters');
if (initialAdminPassword.length < 6) {
throw new Error('INITIAL_ADMIN_PASSWORD must contain at least 6 characters');
}
const result = await pool.request()
@@ -3784,8 +3784,8 @@ app.post('/api/auth/register', accountRecoveryRateLimit, async (req, res) => {
if (!/^[A-Za-z0-9._-]{3,50}$/.test(safeUsername)) {
return res.status(400).json({ success: false, message: 'Username must be 3-50 characters and contain only letters, numbers, dot, underscore or hyphen' });
}
if (safePassword.length < 12 || safePassword.length > 256) {
return res.status(400).json({ success: false, message: 'Password must be between 12 and 256 characters' });
if (safePassword.length < 6 || safePassword.length > 256) {
return res.status(400).json({ success: false, message: 'Password must be between 6 and 256 characters' });
}
const isEmailFormatValid = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(normalizedEmail);
if (!isEmailFormatValid) {
@@ -4120,8 +4120,8 @@ app.post('/api/auth/reset-password', accountRecoveryRateLimit, async (req, res)
return res.status(400).json({ success: false, message: 'Reset token and new password are required' });
}
if (newPassword.length < 12 || newPassword.length > 256) {
return res.status(400).json({ success: false, message: 'New password must be between 12 and 256 characters' });
if (newPassword.length < 6 || newPassword.length > 256) {
return res.status(400).json({ success: false, message: 'New password must be between 6 and 256 characters' });
}
const tokenHash = hashVerificationToken(token);
@@ -4724,8 +4724,8 @@ app.put('/api/users/me', async (req, res) => {
const emailChanged = String(existingUser.Email || '').toLowerCase() !== incomingEmail;
const shouldChangePassword = newPassword.length > 0;
if (shouldChangePassword && (newPassword.length < 12 || newPassword.length > 256)) {
return res.status(400).json({ success: false, message: 'New password must be between 12 and 256 characters' });
if (shouldChangePassword && (newPassword.length < 6 || newPassword.length > 256)) {
return res.status(400).json({ success: false, message: 'New password must be between 6 and 256 characters' });
}
if (shouldChangePassword || emailChanged) {
@@ -4861,8 +4861,8 @@ app.post('/api/users', requireAdmin, async (req, res) => {
if (!/^[A-Za-z0-9._-]{3,50}$/.test(String(username).trim())) {
return res.status(400).json({ success: false, message: 'Username format is invalid' });
}
if (String(password).length < 12 || String(password).length > 256) {
return res.status(400).json({ success: false, message: 'Password must be between 12 and 256 characters' });
if (String(password).length < 6 || String(password).length > 256) {
return res.status(400).json({ success: false, message: 'Password must be between 6 and 256 characters' });
}
const hashedPassword = await hashPassword(password);
@@ -4909,8 +4909,8 @@ app.put('/api/users/:id', requireAdmin, async (req, res) => {
const { email, fullname, roleId, status, isActive, password } = req.body;
const nextPassword = typeof password === 'string' ? password.trim() : '';
const shouldUpdatePassword = nextPassword.length > 0;
if (shouldUpdatePassword && (nextPassword.length < 12 || nextPassword.length > 256)) {
return res.status(400).json({ success: false, message: 'Password must be between 12 and 256 characters' });
if (shouldUpdatePassword && (nextPassword.length < 6 || nextPassword.length > 256)) {
return res.status(400).json({ success: false, message: 'Password must be between 6 and 256 characters' });
}
// Get role name from Roles table