Add admin password reset script with mysql2 dependency
Some checks failed
Deploy to Vercel / deploy (push) Has been cancelled
Deploy to Railway / deploy (push) Has been cancelled

This commit is contained in:
2025-08-22 12:21:24 +09:00
parent 1a053ca047
commit ced3fd03e4
4 changed files with 196 additions and 8 deletions

61
reset-admin.js Normal file
View File

@@ -0,0 +1,61 @@
const bcrypt = require('bcrypt');
const MariaDBHelper = require('./database/mariadb-helper');
async function resetAdminPassword() {
const dbHelper = new MariaDBHelper();
try {
console.log('🔄 관리자 비밀번호 초기화 시작...');
const password = 'Hee150603!';
const saltRounds = 10;
const hashedPassword = await bcrypt.hash(password, saltRounds);
console.log('🔐 해시된 비밀번호:', hashedPassword);
// 관리자 사용자 확인
const existingUser = await dbHelper.getUserByEmail('admin@jaryo.com');
if (existingUser) {
// 기존 사용자 비밀번호 업데이트
const conn = await dbHelper.connect();
const [result] = await conn.execute(
'UPDATE users SET password_hash = ? WHERE email = ?',
[hashedPassword, 'admin@jaryo.com']
);
console.log('✅ 기존 관리자 비밀번호가 업데이트되었습니다.');
} else {
// 새 관리자 사용자 생성
const adminData = {
email: 'admin@jaryo.com',
password_hash: hashedPassword,
name: '관리자',
role: 'admin'
};
const result = await dbHelper.createUser(adminData);
console.log('✅ 새 관리자 사용자가 생성되었습니다.');
}
// 로그인 테스트
const user = await dbHelper.getUserByEmail('admin@jaryo.com');
const isValid = await bcrypt.compare(password, user.password_hash);
console.log('🧪 로그인 테스트 결과:', isValid ? '성공' : '실패');
if (isValid) {
console.log('🎉 관리자 계정 설정 완료!');
console.log('📧 이메일: admin@jaryo.com');
console.log('🔑 비밀번호: Hee150603!');
}
await dbHelper.close();
} catch (error) {
console.error('❌ 오류 발생:', error);
await dbHelper.close();
process.exit(1);
}
}
resetAdminPassword();