Browse Source
Merge pull request #20676 from abpframework/issue-passwordGeneratorUpdates
Angular - Random Password Generator Enhancement for Length
pull/20699/head
oykuermann
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with
15 additions and
1 deletions
-
npm/ng-packs/packages/core/src/lib/utils/generator-utils.ts
|
|
|
@ -1,3 +1,7 @@ |
|
|
|
import { Injector } from '@angular/core'; |
|
|
|
import { ABP } from '../models'; |
|
|
|
import { ConfigStateService } from '../services'; |
|
|
|
|
|
|
|
export function uuid(a?: any): string { |
|
|
|
return a |
|
|
|
? (a ^ ((Math.random() * 16) >> (a / 4))).toString(16) |
|
|
|
@ -16,7 +20,11 @@ export function generateHash(value: string): number { |
|
|
|
return hashed; |
|
|
|
} |
|
|
|
|
|
|
|
export function generatePassword(length = 8) { |
|
|
|
export function generatePassword(injector?: Injector, length = 8) { |
|
|
|
if (injector) { |
|
|
|
length = getRequiredPasswordLength(injector); |
|
|
|
} |
|
|
|
|
|
|
|
length = Math.min(Math.max(4, length), 128); |
|
|
|
|
|
|
|
const lowers = 'abcdefghijklmnopqrstuvwxyz'; |
|
|
|
@ -39,3 +47,9 @@ export function generatePassword(length = 8) { |
|
|
|
|
|
|
|
return password.sort(() => 0.5 - Math.random()).join(''); |
|
|
|
} |
|
|
|
|
|
|
|
function getRequiredPasswordLength(injector: Injector) { |
|
|
|
const configState = injector.get(ConfigStateService); |
|
|
|
const passwordRules: ABP.Dictionary<string> = configState.getSettings('Identity.Password'); |
|
|
|
return Number(passwordRules['Abp.Identity.Password.RequiredLength']) || 8; |
|
|
|
} |
|
|
|
|