siriusscan--sirius
161ef94b4f
Check engine pin consistency / Dockerfile / CI pin consistency (push) Successful in 8s
Sirius CI/CD Pipeline / Detect Changes (push) Successful in 23s
Validate Docker Configuration / Validate Docker Compose Configuration (push) Successful in 47s
Sirius CI/CD Pipeline / Build API (${{ matrix.platform }}) (push) Has been cancelled
Sirius CI/CD Pipeline / Build UI (${{ matrix.platform }}) (push) Has been cancelled
Sirius CI/CD Pipeline / Merge Engine Manifest (push) Has been cancelled
Sirius CI/CD Pipeline / Merge API Manifest (push) Has been cancelled
Sirius CI/CD Pipeline / Merge UI Manifest (push) Has been cancelled
Sirius CI/CD Pipeline / Build Engine (${{ matrix.platform }}) (push) Has been cancelled
Sirius CI/CD Pipeline / Build Infra (${{ matrix.service }}, ${{ matrix.platform }}) (push) Has been cancelled
Sirius CI/CD Pipeline / Merge Infra Manifest (sirius-postgres) (push) Has been cancelled
Sirius CI/CD Pipeline / Merge Infra Manifest (sirius-rabbitmq) (push) Has been cancelled
Sirius CI/CD Pipeline / Merge Infra Manifest (sirius-valkey) (push) Has been cancelled
Sirius CI/CD Pipeline / Integration Test (push) Has been cancelled
Sirius CI/CD Pipeline / Public Stack Contract (push) Has been cancelled
Sirius CI/CD Pipeline / Dispatch Demo Deployment (sirius-demo branch) (push) Has been cancelled
Sirius CI/CD Pipeline / Dispatch Demo Canary (main branch) (push) Has been cancelled
Sirius CI/CD Pipeline / Guard Registry Namespace (push) Has been cancelled
108 行
2.7 KiB
TypeScript
108 行
2.7 KiB
TypeScript
#!/usr/bin/env bun
|
|
/**
|
|
* Reset Password Utility for Sirius Scan
|
|
*
|
|
* This script allows administrators to reset a user's password from the command line.
|
|
*
|
|
* Usage with Bun:
|
|
* bun scripts/reset-password.ts --username <username> --password <new-password>
|
|
*
|
|
* Usage with Node + ts-node:
|
|
* npx ts-node scripts/reset-password.ts --username <username> --password <new-password>
|
|
*/
|
|
|
|
import { PrismaClient } from "@prisma/client";
|
|
import { hash } from "bcrypt";
|
|
import minimist from "minimist";
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function resetPassword(
|
|
username: string,
|
|
newPassword: string
|
|
): Promise<void> {
|
|
try {
|
|
// Validate inputs
|
|
if (!username) {
|
|
throw new Error("Username is required");
|
|
}
|
|
|
|
if (!newPassword || newPassword.length < 8) {
|
|
throw new Error("Password must be at least 8 characters long");
|
|
}
|
|
|
|
// Find the user
|
|
const user = await prisma.user.findFirst({
|
|
where: {
|
|
OR: [{ email: username }, { name: username }],
|
|
},
|
|
});
|
|
|
|
if (!user) {
|
|
throw new Error(`User "${username}" not found`);
|
|
}
|
|
|
|
// Hash the new password
|
|
const hashedPassword = await hash(newPassword, 10);
|
|
|
|
// Update the user's password
|
|
await prisma.user.update({
|
|
where: { id: user.id },
|
|
data: { password: hashedPassword },
|
|
});
|
|
|
|
console.log(`Password for user "${username}" has been reset successfully`);
|
|
} catch (error) {
|
|
console.error(
|
|
"Error resetting password:",
|
|
error instanceof Error ? error.message : error
|
|
);
|
|
process.exit(1);
|
|
} finally {
|
|
// Disconnect from the database
|
|
await prisma.$disconnect();
|
|
}
|
|
}
|
|
|
|
async function main(): Promise<void> {
|
|
const argv = minimist(process.argv.slice(2));
|
|
|
|
// Display help if requested or if no arguments provided
|
|
if (argv.help || argv.h || Object.keys(argv).length === 1) {
|
|
console.log(`
|
|
Reset Password Utility for Sirius Scan
|
|
|
|
Usage with Bun:
|
|
bun scripts/reset-password.ts --username <username> --password <new-password>
|
|
|
|
Usage with Node + ts-node:
|
|
npx ts-node scripts/reset-password.ts --username <username> --password <new-password>
|
|
|
|
Options:
|
|
--username, -u Username or email of the account to reset
|
|
--password, -p New password to set
|
|
--help, -h Display this help message
|
|
`);
|
|
process.exit(0);
|
|
}
|
|
|
|
const username = argv.username || argv.u;
|
|
const password = argv.password || argv.p;
|
|
|
|
if (!username || !password) {
|
|
console.error("Error: Both username and password are required");
|
|
console.log("Use --help for usage information");
|
|
process.exit(1);
|
|
}
|
|
|
|
await resetPassword(username, password);
|
|
}
|
|
|
|
// Run the script
|
|
main()
|
|
.then(() => process.exit(0))
|
|
.catch((error) => {
|
|
console.error("Unhandled error:", error);
|
|
process.exit(1);
|
|
});
|