Skip to content

Commit

Permalink
[PM-8490] - Add generate password to password-protected export (#10539)
Browse files Browse the repository at this point in the history
* WIP generate password in export vault

* finish generate password in export component

* use bitIconButton directive

* add copy link to file password input

* change copy password message
  • Loading branch information
jaasen-livefront authored Aug 21, 2024
1 parent ef4ea18 commit 140b76d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@
bitPasswordInputToggle
[(toggled)]="showFilePassword"
></button>
<button
type="button"
bitIconButton="bwi-generate"
appStopClick
bitSuffix
(click)="generatePassword()"
></button>
<button
type="button"
bitIconButton="bwi-clone"
[disabled]="!filePassword"
appStopClick
bitSuffix
(click)="copyPasswordToClipboard()"
></button>
<bit-hint>{{ "exportPasswordDescription" | i18n }}</bit-hint>
</bit-form-field>
<tools-password-strength [password]="filePassword" [showText]="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { EventType } from "@bitwarden/common/enums";
import { FileDownloadService } from "@bitwarden/common/platform/abstractions/file-download/file-download.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { CollectionService } from "@bitwarden/common/vault/abstractions/collection.service";
import {
Expand All @@ -38,6 +39,7 @@ import {
SelectModule,
ToastService,
} from "@bitwarden/components";
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
import { VaultExportServiceAbstraction } from "@bitwarden/vault-export-core";

import { EncryptedExportType } from "../enums/encrypted-export-type.enum";
Expand Down Expand Up @@ -157,6 +159,8 @@ export class ExportComponent implements OnInit, OnDestroy, AfterViewInit {
protected toastService: ToastService,
protected exportService: VaultExportServiceAbstraction,
protected eventCollectionService: EventCollectionService,
protected passwordGenerationService: PasswordGenerationServiceAbstraction,
private platformUtilsService: PlatformUtilsService,
private policyService: PolicyService,
private logService: LogService,
private formBuilder: UntypedFormBuilder,
Expand Down Expand Up @@ -272,6 +276,22 @@ export class ExportComponent implements OnInit, OnDestroy, AfterViewInit {
}
}

generatePassword = async () => {
const [options] = await this.passwordGenerationService.getOptions();
this.filePasswordValue = await this.passwordGenerationService.generatePassword(options);
this.exportForm.get("filePassword").setValue(this.filePasswordValue);
this.exportForm.get("confirmFilePassword").setValue(this.filePasswordValue);
};

copyPasswordToClipboard = async () => {
this.platformUtilsService.copyToClipboard(this.filePasswordValue);
this.toastService.showToast({
variant: "success",
title: null,
message: this.i18nService.t("valueCopied", this.i18nService.t("password")),
});
};

submit = async () => {
if (this.isFileEncryptedExport && this.filePassword != this.confirmFilePassword) {
this.toastService.showToast({
Expand Down

0 comments on commit 140b76d

Please sign in to comment.