Skip to content

Commit

Permalink
Merge pull request #20676 from abpframework/issue-passwordGeneratorUp…
Browse files Browse the repository at this point in the history
…dates

Angular - Random Password Generator Enhancement for Length
  • Loading branch information
oykuermann authored Sep 2, 2024
2 parents 7a4c552 + 05e0494 commit d4be81f
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion npm/ng-packs/packages/core/src/lib/utils/generator-utils.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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';
Expand All @@ -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;
}

0 comments on commit d4be81f

Please sign in to comment.