admin user
This commit is contained in:
94
backend/scripts/change-password.js
Executable file
94
backend/scripts/change-password.js
Executable file
@@ -0,0 +1,94 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Change Admin Password Script
|
||||
* Usage: node scripts/change-password.js
|
||||
*/
|
||||
|
||||
const readline = require('readline');
|
||||
const bcrypt = require('bcrypt');
|
||||
const path = require('path');
|
||||
|
||||
// Load environment
|
||||
require('dotenv').config({ path: path.join(__dirname, '../.env') });
|
||||
|
||||
// Load database and models
|
||||
const { sequelize } = require('../src/config/database');
|
||||
const { AdminUser } = require('../src/models');
|
||||
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
});
|
||||
|
||||
function question(query) {
|
||||
return new Promise(resolve => rl.question(query, resolve));
|
||||
}
|
||||
|
||||
async function changePassword() {
|
||||
try {
|
||||
console.log('\n╔═══════════════════════════════════════════════════════════╗');
|
||||
console.log('║ 🔐 Change Admin Password - Oltalama Panel ║');
|
||||
console.log('╚═══════════════════════════════════════════════════════════╝\n');
|
||||
|
||||
// Test database connection
|
||||
await sequelize.authenticate();
|
||||
console.log('✅ Database connection successful\n');
|
||||
|
||||
// Get username
|
||||
const username = await question('👤 Enter admin username: ');
|
||||
if (!username) {
|
||||
console.log('❌ Username is required');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Check if user exists
|
||||
const user = await AdminUser.findOne({ where: { username } });
|
||||
if (!user) {
|
||||
console.log('❌ User not found');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Get new password
|
||||
let newPassword;
|
||||
while (true) {
|
||||
newPassword = await question('🔑 Enter new password (min 8 characters): ');
|
||||
if (!newPassword || newPassword.length < 8) {
|
||||
console.log('❌ Password must be at least 8 characters\n');
|
||||
continue;
|
||||
}
|
||||
|
||||
const confirmPassword = await question('🔑 Confirm new password: ');
|
||||
if (newPassword !== confirmPassword) {
|
||||
console.log('❌ Passwords do not match\n');
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Hash password
|
||||
console.log('\n⏳ Updating password...');
|
||||
const hashedPassword = await bcrypt.hash(newPassword, 10);
|
||||
|
||||
// Update password
|
||||
await user.update({
|
||||
password: hashedPassword,
|
||||
});
|
||||
|
||||
console.log('\n✅ Password updated successfully!');
|
||||
console.log(`👤 Username: ${username}\n`);
|
||||
|
||||
} catch (error) {
|
||||
console.error('\n❌ Error changing password:', error.message);
|
||||
process.exit(1);
|
||||
} finally {
|
||||
rl.close();
|
||||
await sequelize.close();
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
// Run
|
||||
changePassword();
|
||||
|
||||
Reference in New Issue
Block a user