// 生成 SHA-256 加密密码的脚本
import crypto from 'crypto';

function sha256(input) {
    return crypto.createHash('sha256').update(input, 'utf8').digest('hex');
}

// 用户信息（用户名 -> 明文密码）
const users = [
    { id: 1, username: 'admin', password: 'admin123456' },
    { id: 2, username: 'zhangsan', password: '123456' },
    { id: 3, username: 'lisi', password: '123456' },
    { id: 4, username: 'wangwu', password: '123456' }
];

console.log('-- SHA-256 加密密码生成结果\n');

users.forEach(user => {
    const encrypted = sha256(user.password);
    console.log(`-- 用户: ${user.username}`);
    console.log(`-- 明文密码: ${user.password}`);
    console.log(`-- SHA-256: ${encrypted}`);
    console.log(`UPDATE user SET password = '${encrypted}' WHERE id = ${user.id};`);
    console.log('');
});

// 生成完整的 SQL 文件内容
console.log('\n-- ==================== 完整的 SQL 更新语句 ====================\n');
console.log('USE demo_database;');
console.log('');
users.forEach(user => {
    const encrypted = sha256(user.password);
    console.log(`UPDATE user SET password = '${encrypted}' WHERE id = ${user.id}; -- ${user.username}: ${user.password}`);
});
