Files
performance-evaluation-system/backend/update-passwords.ts

38 lines
1.1 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import mysql from 'mysql2/promise';
import dotenv from 'dotenv';
dotenv.config();
async function updatePasswords() {
try {
const conn = await mysql.createConnection({
host: process.env.DB_HOST || 'localhost',
port: Number(process.env.DB_PORT) || 3306,
user: process.env.DB_USER || 'root',
password: process.env.DB_PASSWORD || '',
database: process.env.DB_NAME || 'employee_performance',
});
console.log('设置所有用户密码为123456明文...');
const password = '123456';
// 更新所有用户密码
await conn.query('UPDATE user SET password = ?', [password]);
console.log('✓ 所有用户密码已更新为123456');
// 验证更新
const [rows] = await conn.query('SELECT username, password FROM user LIMIT 1');
const user = (rows as any)[0];
const passwordMatch = user.password === '123456';
console.log('密码验证:', passwordMatch ? '成功' : '失败');
await conn.end();
process.exit(0);
} catch (error: any) {
console.error('错误:', error.message);
process.exit(1);
}
}
updatePasswords();