fixed phonetic password generation

This commit is contained in:
antelle 2021-05-08 17:13:10 +02:00
parent 966d814281
commit 0ce436c2e9
No known key found for this signature in database
GPG Key ID: 63C9777AAB7C563C
2 changed files with 7 additions and 4 deletions

View File

@ -312,7 +312,8 @@ function generate(options) {
word: '',
opts: options
};
while (wordObj.word.length < length) {
const safeMaxLength = length + 5;
while (wordObj.word.length < safeMaxLength) {
addSyllable(wordObj);
}
return postProcess(wordObj).substr(0, length);

View File

@ -41,9 +41,11 @@ describe('PasswordGenerator', () => {
});
it('should generate a pronounceable password', () => {
expect(PasswordGenerator.generate({ length: 10, name: 'Pronounceable' })).to.match(
/^[a-zA-Z]{10}$/
);
for (let i = 0; i < 1000; i++) {
expect(PasswordGenerator.generate({ length: 10, name: 'Pronounceable' })).to.match(
/^[a-zA-Z]{10}$/
);
}
});
it('should generate a password with pattern', () => {