Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | import { CustomMathsService } from "./CustomMathsService";
export class PasswordGeneratorService {
static getDefaultConfig = () => {
return {
length: 16,
useUppercase: true,
useLowercase: true,
useDigits: true,
useSpecialChars: true,
avoidAmbiguousCharacters: false,
requireEveryCharType: true
};
};
static generate = (configuration) => {
let generatedPassword = "";
let characterPool = "";
let lowercaseCharacters = "abcdefghjkmnpqrstuvwxyz";
let uppercaseCharacters = "ABCDEFGHJKMNPQRSTUVWXYZ";
let digits = "23456789";
let specialCharacters = ".!@#$%^&*";
if (!configuration.avoidAmbiguousCharacters) {
lowercaseCharacters += "ilo";
uppercaseCharacters += "ILO";
digits += "10";
}
if (configuration.useLowercase) {
characterPool += lowercaseCharacters;
}
if (configuration.useUppercase) {
characterPool += uppercaseCharacters;
}
if (configuration.useDigits) {
characterPool += digits;
}
if (configuration.useSpecialChars) {
characterPool += specialCharacters;
}
for (let generatorPosition = 0; generatorPosition < configuration.length; generatorPosition++) {
let customCharacterPool = characterPool;
if (configuration.requireEveryCharType) {
customCharacterPool = "";
switch (generatorPosition) {
case 0:
customCharacterPool += lowercaseCharacters;
break;
case 1:
customCharacterPool += uppercaseCharacters;
break;
case 2:
customCharacterPool += digits;
break;
case 3:
customCharacterPool += specialCharacters;
break;
default:
customCharacterPool = characterPool;
break;
}
}
generatedPassword += customCharacterPool.charAt(CustomMathsService.getSecureRandomInt(0, customCharacterPool.length - 1));
}
return PasswordGeneratorService.shuffle(generatedPassword);
};
static shuffle = (input) => {
return input.split('').sort(function () {
return 0.5 - (CustomMathsService.getSecureRandomInt(0, 100) / 100);
}).join('');
};
}
|