Skip to content

Commit

Permalink
fix(tenant-management): use regex while generating password
Browse files Browse the repository at this point in the history
use regex while generating password

GH-47
  • Loading branch information
Surbhi-sharma1 committed Oct 17, 2024
1 parent ec347b9 commit e1b73b3
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import {Provider} from '@loopback/context';

import {ConfigureIdpFunc, IdpDetails, IdPKey, IdpResp} from '../../types';
import {ManagementClient, PostOrganizationsRequest, UserCreate} from 'auth0';
import {randomBytes} from 'crypto';
import {repository} from '@loopback/repository';

import {randomBytes} from 'crypto';
import {HttpErrors} from '@loopback/rest';
import {TenantMgmtConfigRepository} from '../../repositories';

Expand Down Expand Up @@ -57,17 +56,19 @@ export class Auth0IdpProvider implements Provider<ConfigureIdpFunc<IdpResp>> {
enabled_connections: configValue.enabled_connections,
};
function generateStrongPassword(length: number): string {
const charset =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+~`|}{[]:;?><,./-=';
const regex = /[A-Za-z0-9!@#$%^&*()_+~`|}{[\]:;?><,./-=]/;
const validChars: string[] = [];

// Generate random bytes
for (let i = 33; i <= 126; i++) {
const char = String.fromCharCode(i);
if (regex.test(char)) {
validChars.push(char);
}
}
const randomBytesArray = randomBytes(length);

// Map each byte to a character in the charset
const password = Array.from(randomBytesArray)
.map(byte => charset[byte % charset.length])
.map(byte => validChars[byte % validChars.length])
.join('');

return password;
}

Expand Down

0 comments on commit e1b73b3

Please sign in to comment.