appendRandomNumberToRandomWord
This commit is contained in:
parent
a017f72506
commit
8375f7381a
|
@ -172,17 +172,15 @@ export class PasswordGenerationService implements PasswordGenerationServiceAbstr
|
||||||
if (o.wordSeparator == null || o.wordSeparator.length === 0 || o.wordSeparator.length > 1) {
|
if (o.wordSeparator == null || o.wordSeparator.length === 0 || o.wordSeparator.length > 1) {
|
||||||
o.wordSeparator = ' ';
|
o.wordSeparator = ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (o.capitalize == null) {
|
if (o.capitalize == null) {
|
||||||
o.addCommonRequirements = false;
|
o.addCommonRequirements = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (o.includeNumber == null) {
|
if (o.includeNumber == null) {
|
||||||
o.includeNumber = false;
|
o.includeNumber = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const listLength = EEFLongWordList.length - 1;
|
const listLength = EEFLongWordList.length - 1;
|
||||||
let wordList = new Array(o.numWords);
|
const wordList = new Array(o.numWords);
|
||||||
for (let i = 0; i < o.numWords; i++) {
|
for (let i = 0; i < o.numWords; i++) {
|
||||||
const wordIndex = await this.cryptoService.randomNumber(0, listLength);
|
const wordIndex = await this.cryptoService.randomNumber(0, listLength);
|
||||||
if (o.capitalize) {
|
if (o.capitalize) {
|
||||||
|
@ -193,9 +191,8 @@ export class PasswordGenerationService implements PasswordGenerationServiceAbstr
|
||||||
}
|
}
|
||||||
|
|
||||||
if (o.includeNumber) {
|
if (o.includeNumber) {
|
||||||
return await this.insertNumber(wordList.join(o.wordSeparator));
|
await this.appendRandomNumberToRandomWord(wordList);
|
||||||
}
|
}
|
||||||
|
|
||||||
return wordList.join(o.wordSeparator);
|
return wordList.join(o.wordSeparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,10 +276,13 @@ export class PasswordGenerationService implements PasswordGenerationServiceAbstr
|
||||||
return str.charAt(0).toUpperCase() + str.slice(1);
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async insertNumber(word: string) {
|
private async appendRandomNumberToRandomWord(wordList: string[]) {
|
||||||
const charIndex = await this.cryptoService.randomNumber(0, word.length - 1);
|
if (wordList == null || wordList.length < 0) {
|
||||||
const addedNumber = await this.cryptoService.randomNumber(0, 9);
|
return;
|
||||||
return word.substring(0, charIndex) + addedNumber + word.substring(charIndex, word.length);
|
}
|
||||||
|
const index = await this.cryptoService.randomNumber(0, wordList.length - 1);
|
||||||
|
const num = await this.cryptoService.randomNumber(0, 9);
|
||||||
|
wordList[index] = wordList[index] + num;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async encryptHistory(history: GeneratedPasswordHistory[]): Promise<GeneratedPasswordHistory[]> {
|
private async encryptHistory(history: GeneratedPasswordHistory[]): Promise<GeneratedPasswordHistory[]> {
|
||||||
|
|
Loading…
Reference in New Issue