feat: implement password generation method; enhance database creation with secure password generation
This commit is contained in:
@ -103,6 +103,27 @@ export class DatabaseManagerService extends DatabaseEncryptionService {
|
||||
|
||||
return connectionOptions;
|
||||
}
|
||||
generatePassword(length: number = 16): string {
|
||||
const upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
const lowerCase = "abcdefghijklmnopqrstuvwxyz";
|
||||
const numbers = "0123456789";
|
||||
const symbols = "!@#$%^&*()_+[]{}|;:,.<>?";
|
||||
|
||||
// Ensure at least one character from each required category
|
||||
let password = "";
|
||||
password += upperCase.charAt(Math.floor(Math.random() * upperCase.length));
|
||||
password += numbers.charAt(Math.floor(Math.random() * numbers.length));
|
||||
password += symbols.charAt(Math.floor(Math.random() * symbols.length));
|
||||
|
||||
// Fill the rest with random characters from all categories
|
||||
const allChars = upperCase + lowerCase + numbers + symbols;
|
||||
for (let i = 3; i < length; i++) {
|
||||
password += allChars.charAt(Math.floor(Math.random() * allChars.length));
|
||||
}
|
||||
|
||||
// Shuffle the password to randomize the position of required characters
|
||||
return password.split('').sort(() => Math.random() - 0.5).join('');
|
||||
}
|
||||
|
||||
async createDatabase(projectId: string): Promise<Database> {
|
||||
const node = await this.databaseNodeService.findOptimalNode();
|
||||
@ -121,7 +142,7 @@ export class DatabaseManagerService extends DatabaseEncryptionService {
|
||||
const q_username = `q_user_${Math.random().toString(36).substring(2, 8)}`;
|
||||
const databaseName = `db_${Math.random().toString(36).substring(2, 8)}`;
|
||||
const password = this.encryptPassword(
|
||||
Math.random().toString(36).substring(2, 10)
|
||||
this.generatePassword()
|
||||
);
|
||||
|
||||
await this.databaseNodeService.initDatabase(
|
||||
|
||||
Reference in New Issue
Block a user