bitwarden-estensione-browser/apps/web/src/app/reports/weak-passwords-report.compo...

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

126 lines
4.1 KiB
TypeScript
Raw Normal View History

2018-12-11 23:49:51 +01:00
import { Component, OnInit } from "@angular/core";
2022-06-14 17:10:53 +02:00
import { ModalService } from "@bitwarden/angular/services/modal.service";
import { CipherService } from "@bitwarden/common/abstractions/cipher.service";
import { MessagingService } from "@bitwarden/common/abstractions/messaging.service";
import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwordGeneration.service";
import { PasswordRepromptService } from "@bitwarden/common/abstractions/passwordReprompt.service";
import { StateService } from "@bitwarden/common/abstractions/state.service";
import { CipherType } from "@bitwarden/common/enums/cipherType";
import { CipherView } from "@bitwarden/common/models/view/cipherView";
2018-12-11 23:49:51 +01:00
2018-12-12 15:11:10 +01:00
import { CipherReportComponent } from "./cipher-report.component";
2018-12-11 23:49:51 +01:00
@Component({
selector: "app-weak-passwords-report",
templateUrl: "weak-passwords-report.component.html",
})
2018-12-12 15:11:10 +01:00
export class WeakPasswordsReportComponent extends CipherReportComponent implements OnInit {
2018-12-11 23:49:51 +01:00
passwordStrengthMap = new Map<string, [string, string]>();
2018-12-11 23:49:51 +01:00
private passwordStrengthCache = new Map<string, number>();
2018-12-12 17:22:11 +01:00
constructor(
protected cipherService: CipherService,
protected passwordGenerationService: PasswordGenerationService,
[Account Switching] [Refactor] Implement new account centric services (#1220) * [chore] updated services.module to use account services * [refactor] sorted services provided by services.module * [chore] removed references to deleted jslib services * [chore] used activeAccount over storageService for account level storage items * [chore] resolved linter warnings * Refactor activeAccountService to stateService * [bug] Remove uneeded calls to state service on logout This was causing console erros on logout. Clearing of data is handled fully in dedicated services, clearing them in state afterwards is essentially a redundant call. * [bug] Add back null locked callback to VaultTimeoutService * Move call to get showUpdateKey * [bug] Ensure HtmlStorageService does not override StateService options and locations * [bug] Adjust theme logic to pull from the new storage locations * [bug] Correct theme not sticking on refresh * [bug] Add enableFullWidth to the account model * [bug] fix theme option empty when light is selected * [bug] init state on application start * [bug] Reinit state when coming back from a lock * [style] Fix lint complaints * [bug] Clean state on logout * [chore] Resolved merge issues * [bug] Correct default for enableGravitars * Bump angular to 12. * Remove angular.json * Bump rxjs * Fix build errors, remove file-loader with asset/resource * Use contenthash * Bump jslib * Bump ngx-toastr * [chore] resolve issues from merge * [chore] resolve issues from merge * [bug] Add missing bracket * Use newer import syntax * [bug] Correct service orge * [style] Fix lint complaints * [chore] update jslib * [review] Address code review * [review] Address code review * [review] Rename providerService to webProviderService Co-authored-by: Robyn MacCallum <robyntmaccallum@gmail.com> Co-authored-by: Hinton <oscar@oscarhinton.com>
2021-12-14 17:10:26 +01:00
modalService: ModalService,
2018-12-12 17:22:11 +01:00
messagingService: MessagingService,
[Account Switching] [Refactor] Implement new account centric services (#1220) * [chore] updated services.module to use account services * [refactor] sorted services provided by services.module * [chore] removed references to deleted jslib services * [chore] used activeAccount over storageService for account level storage items * [chore] resolved linter warnings * Refactor activeAccountService to stateService * [bug] Remove uneeded calls to state service on logout This was causing console erros on logout. Clearing of data is handled fully in dedicated services, clearing them in state afterwards is essentially a redundant call. * [bug] Add back null locked callback to VaultTimeoutService * Move call to get showUpdateKey * [bug] Ensure HtmlStorageService does not override StateService options and locations * [bug] Adjust theme logic to pull from the new storage locations * [bug] Correct theme not sticking on refresh * [bug] Add enableFullWidth to the account model * [bug] fix theme option empty when light is selected * [bug] init state on application start * [bug] Reinit state when coming back from a lock * [style] Fix lint complaints * [bug] Clean state on logout * [chore] Resolved merge issues * [bug] Correct default for enableGravitars * Bump angular to 12. * Remove angular.json * Bump rxjs * Fix build errors, remove file-loader with asset/resource * Use contenthash * Bump jslib * Bump ngx-toastr * [chore] resolve issues from merge * [chore] resolve issues from merge * [bug] Add missing bracket * Use newer import syntax * [bug] Correct service orge * [style] Fix lint complaints * [chore] update jslib * [review] Address code review * [review] Address code review * [review] Rename providerService to webProviderService Co-authored-by: Robyn MacCallum <robyntmaccallum@gmail.com> Co-authored-by: Hinton <oscar@oscarhinton.com>
2021-12-14 17:10:26 +01:00
stateService: StateService,
2018-12-12 17:22:11 +01:00
passwordRepromptService: PasswordRepromptService
2021-12-17 15:57:11 +01:00
) {
2018-12-12 17:22:11 +01:00
super(modalService, messagingService, true, stateService, passwordRepromptService);
2021-12-17 15:57:11 +01:00
}
2018-12-12 17:22:11 +01:00
2018-12-14 20:42:04 +01:00
async ngOnInit() {
[Account Switching] [Refactor] Implement new account centric services (#1220) * [chore] updated services.module to use account services * [refactor] sorted services provided by services.module * [chore] removed references to deleted jslib services * [chore] used activeAccount over storageService for account level storage items * [chore] resolved linter warnings * Refactor activeAccountService to stateService * [bug] Remove uneeded calls to state service on logout This was causing console erros on logout. Clearing of data is handled fully in dedicated services, clearing them in state afterwards is essentially a redundant call. * [bug] Add back null locked callback to VaultTimeoutService * Move call to get showUpdateKey * [bug] Ensure HtmlStorageService does not override StateService options and locations * [bug] Adjust theme logic to pull from the new storage locations * [bug] Correct theme not sticking on refresh * [bug] Add enableFullWidth to the account model * [bug] fix theme option empty when light is selected * [bug] init state on application start * [bug] Reinit state when coming back from a lock * [style] Fix lint complaints * [bug] Clean state on logout * [chore] Resolved merge issues * [bug] Correct default for enableGravitars * Bump angular to 12. * Remove angular.json * Bump rxjs * Fix build errors, remove file-loader with asset/resource * Use contenthash * Bump jslib * Bump ngx-toastr * [chore] resolve issues from merge * [chore] resolve issues from merge * [bug] Add missing bracket * Use newer import syntax * [bug] Correct service orge * [style] Fix lint complaints * [chore] update jslib * [review] Address code review * [review] Address code review * [review] Rename providerService to webProviderService Co-authored-by: Robyn MacCallum <robyntmaccallum@gmail.com> Co-authored-by: Hinton <oscar@oscarhinton.com>
2021-12-14 17:10:26 +01:00
if (await this.checkAccess()) {
await super.load();
2018-12-12 15:11:10 +01:00
}
2021-12-17 15:57:11 +01:00
}
2018-12-11 23:49:51 +01:00
2018-12-12 15:29:51 +01:00
async setCiphers() {
2018-12-14 19:56:01 +01:00
const allCiphers = await this.getAllCiphers();
const weakPasswordCiphers: CipherView[] = [];
const isUserNameNotEmpty = (c: CipherView): boolean => {
2018-12-12 15:29:51 +01:00
return c.login.username != null && c.login.username.trim() !== "";
2021-12-17 15:57:11 +01:00
};
2018-12-12 15:29:51 +01:00
const getCacheKey = (c: CipherView): string => {
return c.login.password + "_____" + (isUserNameNotEmpty(c) ? c.login.username : "");
2018-12-11 23:49:51 +01:00
};
allCiphers.forEach((c) => {
if (
c.type !== CipherType.Login ||
c.login.password == null ||
c.login.password === "" ||
c.isDeleted
) {
2018-12-11 23:49:51 +01:00
return;
}
const hasUserName = isUserNameNotEmpty(c);
const cacheKey = getCacheKey(c);
if (!this.passwordStrengthCache.has(cacheKey)) {
let userInput: string[] = [];
if (hasUserName) {
const atPosition = c.login.username.indexOf("@");
if (atPosition > -1) {
userInput = userInput
.concat(
c.login.username
.substr(0, atPosition)
.trim()
.toLowerCase()
.split(/[^A-Za-z0-9]/)
2021-12-17 15:57:11 +01:00
)
.filter((i) => i.length >= 3);
} else {
userInput = c.login.username
.trim()
.toLowerCase()
.split(/[^A-Za-z0-9]/)
.filter((i) => i.length >= 3);
2021-12-17 15:57:11 +01:00
}
}
const result = this.passwordGenerationService.passwordStrength(
c.login.password,
userInput.length > 0 ? userInput : null
);
this.passwordStrengthCache.set(cacheKey, result.score);
2018-12-12 17:22:11 +01:00
}
const score = this.passwordStrengthCache.get(cacheKey);
if (score != null && score <= 2) {
2018-12-12 17:22:11 +01:00
this.passwordStrengthMap.set(c.id, this.scoreKey(score));
weakPasswordCiphers.push(c);
}
2018-12-11 23:49:51 +01:00
});
weakPasswordCiphers.sort((a, b) => {
return (
this.passwordStrengthCache.get(getCacheKey(a)) -
this.passwordStrengthCache.get(getCacheKey(b))
);
});
2018-12-11 23:49:51 +01:00
this.ciphers = weakPasswordCiphers;
}
2018-12-14 20:42:04 +01:00
protected getAllCiphers(): Promise<CipherView[]> {
return this.cipherService.getAllDecrypted();
}
protected canManageCipher(c: CipherView): boolean {
// this will only ever be false from the org view;
return true;
}
2018-12-11 23:49:51 +01:00
private scoreKey(score: number): [string, string] {
switch (score) {
case 4:
return ["strong", "success"];
case 3:
return ["good", "primary"];
case 2:
return ["weak", "warning"];
default:
return ["veryWeak", "danger"];
}
2021-12-17 15:57:11 +01:00
}
2018-12-11 23:49:51 +01:00
}