diff --git a/components.d.ts b/components.d.ts index 3e65c3cc..02e70835 100644 --- a/components.d.ts +++ b/components.d.ts @@ -141,8 +141,10 @@ declare module '@vue/runtime-core' { NLayout: typeof import('naive-ui')['NLayout'] NLayoutSider: typeof import('naive-ui')['NLayoutSider'] NMenu: typeof import('naive-ui')['NMenu'] - NSpace: typeof import('naive-ui')['NSpace'] - NTable: typeof import('naive-ui')['NTable'] + NP: typeof import('naive-ui')['NP'] + NScrollbar: typeof import('naive-ui')['NScrollbar'] + NSlider: typeof import('naive-ui')['NSlider'] + NSwitch: typeof import('naive-ui')['NSwitch'] NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default'] OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default'] PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default'] diff --git a/locales/en.yml b/locales/en.yml index d03d80d3..5063cee4 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -391,4 +391,4 @@ tools: text-to-binary: title: Text to ASCII binary - description: Convert text to its ASCII binary representation and vice-versa. + description: Convert text to its ASCII binary representation and vice-versa. \ No newline at end of file diff --git a/src/tools/token-generator/token-generator.service.test.ts b/src/tools/token-generator/token-generator.service.test.ts index 604f5a89..ad4552ce 100644 --- a/src/tools/token-generator/token-generator.service.test.ts +++ b/src/tools/token-generator/token-generator.service.test.ts @@ -94,5 +94,19 @@ describe('token-generator', () => { expect(token).toHaveLength(256); expect(token).toMatch(/^[a-zA-Z]+$/); }); + + it('should generate a random string with just numbers except 1 and 2 if only withNumbers is set and deniedChars contains 1 and 2', () => { + const token = createToken({ + withLowercase: false, + withUppercase: false, + withNumbers: true, + withSymbols: false, + length: 256, + deniedChars: '12', + }); + + expect(token).toHaveLength(256); + expect(token).toMatch(/^[03456789]+$/); + }); }); }); diff --git a/src/tools/token-generator/token-generator.service.ts b/src/tools/token-generator/token-generator.service.ts index f928a415..ad22628a 100644 --- a/src/tools/token-generator/token-generator.service.ts +++ b/src/tools/token-generator/token-generator.service.ts @@ -5,6 +5,7 @@ export function createToken({ withLowercase = true, withNumbers = true, withSymbols = false, + deniedChars = '', length = 64, alphabet, }: { @@ -12,15 +13,17 @@ export function createToken({ withLowercase?: boolean withNumbers?: boolean withSymbols?: boolean + deniedChars?: string length?: number alphabet?: string }) { - const allAlphabet = alphabet ?? [ - withUppercase ? 'ABCDEFGHIJKLMOPQRSTUVWXYZ' : '', - withLowercase ? 'abcdefghijklmopqrstuvwxyz' : '', - withNumbers ? '0123456789' : '', - withSymbols ? '.,;:!?./-"\'#{([-|\\@)]=}*+' : '', - ].join(''); + const allAlphabet = (alphabet ?? ( + (withUppercase ? 'ABCDEFGHIJKLMOPQRSTUVWXYZ' : '') + + (withLowercase ? 'abcdefghijklmopqrstuvwxyz' : '') + + (withNumbers ? '0123456789' : '') + + (withSymbols ? '.,;:!?./-"\'#{([-|\\@)]=}*+' : '') + )).split('').filter(c => !(deniedChars?.includes(c))).join(''); - return shuffleString(allAlphabet.repeat(length)).substring(0, length); + const len = length < 1 ? 1 : length; + return shuffleString(allAlphabet.repeat(len)).substring(0, len); } diff --git a/src/tools/token-generator/token-generator.tool.vue b/src/tools/token-generator/token-generator.tool.vue index fe53edcd..3000fea6 100644 --- a/src/tools/token-generator/token-generator.tool.vue +++ b/src/tools/token-generator/token-generator.tool.vue @@ -1,75 +1,88 @@ - - - - - + + + + - - - - + + + + + + - - - - - - - - - - + + + + + + + + - + + + + + + + {{ t('tools.token-generator.button.copy') }} - + {{ t('tools.token-generator.button.refresh') }}