mirror of
https://github.com/margrop/wrong-notebook.git
synced 2026-12-02 04:09:21 +08:00
40 lines
1.0 KiB
JavaScript
40 lines
1.0 KiB
JavaScript
const { PrismaClient } = require('@prisma/client');
|
|
const { hash } = require('bcryptjs');
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
const users = await prisma.user.findMany();
|
|
console.log('Existing users:');
|
|
users.forEach(u => console.log(`- ${u.email} (${u.name || 'No Name'})`));
|
|
|
|
const email = process.argv[2];
|
|
const newPassword = process.argv[3];
|
|
|
|
if (!email || !newPassword) {
|
|
console.log('\nUsage: node reset-password.js <email> <new_password>');
|
|
return;
|
|
}
|
|
|
|
const hashedPassword = await hash(newPassword, 12);
|
|
|
|
try {
|
|
await prisma.user.update({
|
|
where: { email },
|
|
data: { password: hashedPassword },
|
|
});
|
|
console.log(`\nPassword for ${email} has been reset successfully.`);
|
|
} catch (e) {
|
|
console.error(`\nError resetting password: ${e.message}`);
|
|
}
|
|
}
|
|
|
|
main()
|
|
.catch(e => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|