1 import { Injectable } from '@angular/core';
3 import _ from 'lodash';
4 import { Observable } from 'rxjs';
5 import { map } from 'rxjs/operators';
7 import { SettingsService } from '../api/settings.service';
8 import { CdPwdPolicySettings } from '../models/cd-pwd-policy-settings';
13 export class PasswordPolicyService {
14 constructor(private settingsService: SettingsService) {}
16 getHelpText(): Observable<string> {
17 return this.settingsService.getStandardSettings().pipe(
18 map((resp: { [key: string]: any }) => {
19 const settings = new CdPwdPolicySettings(resp);
20 let helpText: string[] = [];
21 if (settings.pwdPolicyEnabled) {
22 helpText.push($localize`Required rules for passwords:`);
23 const i18nHelp: { [key: string]: string } = {
24 pwdPolicyCheckLengthEnabled: $localize`Must contain at least ${settings.pwdPolicyMinLength} characters`,
25 pwdPolicyCheckOldpwdEnabled: $localize`Must not be the same as the previous one`,
26 pwdPolicyCheckUsernameEnabled: $localize`Cannot contain the username`,
27 pwdPolicyCheckExclusionListEnabled: $localize`Cannot contain any configured keyword`,
28 pwdPolicyCheckRepetitiveCharsEnabled: $localize`Cannot contain any repetitive characters e.g. "aaa"`,
29 pwdPolicyCheckSequentialCharsEnabled: $localize`Cannot contain any sequential characters e.g. "abc"`,
30 pwdPolicyCheckComplexityEnabled: $localize`Must consist of characters from the following groups:
33 * Special chars: !"#$%& '()*+,-./:;<=>?@[\\]^_\`{{|}}~
34 * Any other characters (signs)`
36 helpText = helpText.concat(
38 .filter((key) => _.get(settings, key))
39 .map((key) => '- ' + _.get(i18nHelp, key))
42 return helpText.join('\n');
48 * Helper function to map password policy credits to a CSS class.
49 * @param credits The password policy credits.
50 * @return The name of the CSS class.
52 mapCreditsToCssClass(credits: number): string {
53 let result = 'very-strong';
56 } else if (credits < 15) {
58 } else if (credits < 20) {
60 } else if (credits < 25) {