]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/services/password-policy.service.ts
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / services / password-policy.service.ts
CommitLineData
9f95a23c
TL
1import { Injectable } from '@angular/core';
2
f67539c2 3import _ from 'lodash';
9f95a23c
TL
4import { Observable } from 'rxjs';
5import { map } from 'rxjs/operators';
6
7import { SettingsService } from '../api/settings.service';
8import { CdPwdPolicySettings } from '../models/cd-pwd-policy-settings';
9
10@Injectable({
11 providedIn: 'root'
12})
13export class PasswordPolicyService {
f67539c2 14 constructor(private settingsService: SettingsService) {}
9f95a23c
TL
15
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) {
f67539c2 22 helpText.push($localize`Required rules for passwords:`);
9f95a23c 23 const i18nHelp: { [key: string]: string } = {
f67539c2
TL
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:
e306af50
TL
31 * Alphabetic a-z, A-Z
32 * Numbers 0-9
33 * Special chars: !"#$%& '()*+,-./:;<=>?@[\\]^_\`{{|}}~
34 * Any other characters (signs)`
9f95a23c
TL
35 };
36 helpText = helpText.concat(
37 _.keys(i18nHelp)
38 .filter((key) => _.get(settings, key))
39 .map((key) => '- ' + _.get(i18nHelp, key))
40 );
41 }
42 return helpText.join('\n');
43 })
44 );
45 }
46
47 /**
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.
51 */
52 mapCreditsToCssClass(credits: number): string {
53 let result = 'very-strong';
54 if (credits < 10) {
55 result = 'too-weak';
56 } else if (credits < 15) {
57 result = 'weak';
58 } else if (credits < 20) {
59 result = 'ok';
60 } else if (credits < 25) {
61 result = 'strong';
62 }
63 return result;
64 }
65}