const bcrypt = require('bcrypt'); async function testBcrypt() { try { console.log('开始测试bcrypt功能...'); // 测试密码哈希 const password = 'testPassword123'; console.log('原始密码:', password); // 生成哈希 const saltRounds = 10; const hash = await bcrypt.hash(password, saltRounds); console.log('生成的哈希:', hash); // 验证密码 const isValid = await bcrypt.compare(password, hash); console.log('密码验证结果:', isValid); // 测试错误密码 const isInvalid = await bcrypt.compare('wrongPassword', hash); console.log('错误密码验证结果:', isInvalid); console.log('✅ bcrypt功能测试成功!'); return true; } catch (error) { console.error('❌ bcrypt功能测试失败:', error); return false; } } testBcrypt().then(success => { process.exit(success ? 0 : 1); });