mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 08:43:33 +00:00
move last sync and generapte password out to other commands
This commit is contained in:
31
src/commands/generate.command.ts
Normal file
31
src/commands/generate.command.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import * as program from 'commander';
|
||||
|
||||
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
|
||||
|
||||
import { Response } from '../models/response';
|
||||
import { StringResponse } from '../models/response/stringResponse';
|
||||
|
||||
export class GenerateCommand {
|
||||
constructor(private passwordGenerationService: PasswordGenerationService) { }
|
||||
|
||||
async run(cmd: program.Command): Promise<Response> {
|
||||
const options = {
|
||||
uppercase: cmd.uppercase || false,
|
||||
lowercase: cmd.lowercase || false,
|
||||
number: cmd.number || false,
|
||||
special: cmd.special || false,
|
||||
length: cmd.length || 14,
|
||||
};
|
||||
if (!options.uppercase && !options.lowercase && !options.special && !options.number) {
|
||||
options.lowercase = true;
|
||||
options.uppercase = true;
|
||||
options.number = true;
|
||||
}
|
||||
if (options.length < 5) {
|
||||
options.length = 5;
|
||||
}
|
||||
const password = await this.passwordGenerationService.generatePassword(options);
|
||||
const res = new StringResponse(password);
|
||||
return Response.success(res);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user