mirror of
https://github.com/bitwarden/browser.git
synced 2024-10-30 08:10:34 +01:00
get password
This commit is contained in:
parent
86700fe7ef
commit
8fd74688b1
@ -5,6 +5,7 @@ import { CipherType } from 'jslib/enums/cipherType';
|
||||
import { CipherService } from 'jslib/abstractions/cipher.service';
|
||||
import { CollectionService } from 'jslib/abstractions/collection.service';
|
||||
import { FolderService } from 'jslib/abstractions/folder.service';
|
||||
import { PasswordGenerationService } from 'jslib/abstractions/passwordGeneration.service';
|
||||
import { SyncService } from 'jslib/abstractions/sync.service';
|
||||
import { TotpService } from 'jslib/abstractions/totp.service';
|
||||
|
||||
@ -28,10 +29,10 @@ import { SecureNote } from '../models/secureNote';
|
||||
export class GetCommand {
|
||||
constructor(private cipherService: CipherService, private folderService: FolderService,
|
||||
private collectionService: CollectionService, private totpService: TotpService,
|
||||
private syncService: SyncService) { }
|
||||
private syncService: SyncService, private passwordGenerationService: PasswordGenerationService) { }
|
||||
|
||||
async run(object: string, id: string, cmd: program.Command): Promise<Response> {
|
||||
if (id == null && object !== 'lastsync') {
|
||||
if (id == null && object !== 'lastsync' && object !== 'password') {
|
||||
return Response.badRequest('`id` argument is required.');
|
||||
}
|
||||
|
||||
@ -48,6 +49,8 @@ export class GetCommand {
|
||||
return await this.getTemplate(id);
|
||||
case 'lastsync':
|
||||
return await this.getLastSync();
|
||||
case 'password':
|
||||
return await this.getPassword(cmd);
|
||||
default:
|
||||
return Response.badRequest('Unknown object.');
|
||||
}
|
||||
@ -153,4 +156,25 @@ export class GetCommand {
|
||||
const res = new StringResponse(lastSyncDate == null ? null : lastSyncDate.toISOString());
|
||||
return Response.success(res);
|
||||
}
|
||||
|
||||
private async getPassword(cmd: program.Command) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -107,10 +107,16 @@ export class Program {
|
||||
program
|
||||
.command('get <object> [id]')
|
||||
.description('Get an object.')
|
||||
.option('--uppercase', 'Include uppercase characters.')
|
||||
.option('--lowercase', 'Include lowercase characters.')
|
||||
.option('--number', 'Include numeric characters.')
|
||||
.option('--special', 'Include special characters.')
|
||||
.option('--length <length>', 'Password length.')
|
||||
.action(async (object, id, cmd) => {
|
||||
await this.exitIfLocked();
|
||||
const command = new GetCommand(this.main.cipherService, this.main.folderService,
|
||||
this.main.collectionService, this.main.totpService, this.main.syncService);
|
||||
this.main.collectionService, this.main.totpService, this.main.syncService,
|
||||
this.main.passwordGenerationService);
|
||||
const response = await command.run(object, id, cmd);
|
||||
this.processResponse(response, cmd);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user