mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-22 14:01:42 +03:00
feat(Token Generator): add ambigous chars exclusion by default
Fix #1800
This commit is contained in:
1 parent
b662c6b356
commit
8b19bf00c3
3 files changed
+61
-23
No files matched your search
@@ -184,6 +184,7 @@ tools:
|
|||||||
label-denied-characters-ie-visually-similar-oo01li-or-punctuations: Denied Characters (ie, visually similar { oO01lI } or punctuations)
|
label-denied-characters-ie-visually-similar-oo01li-or-punctuations: Denied Characters (ie, visually similar { oO01lI } or punctuations)
|
||||||
placeholder-put-characters-to-deny-from-token: Put characters to deny from token
|
placeholder-put-characters-to-deny-from-token: Put characters to deny from token
|
||||||
label-number-of-token-to-generate: Number of token to generate
|
label-number-of-token-to-generate: Number of token to generate
|
||||||
|
label-allow-ambiguous-characters: Allows Visually Ambigous Characters
|
||||||
percentage-calculator:
|
percentage-calculator:
|
||||||
title: Percentage calculator
|
title: Percentage calculator
|
||||||
description: >-
|
description: >-
|
||||||
|
|||||||
@@ -7,25 +7,32 @@ export function createToken({
|
|||||||
withHexaNumbers = false,
|
withHexaNumbers = false,
|
||||||
withSymbols = false,
|
withSymbols = false,
|
||||||
deniedChars = '',
|
deniedChars = '',
|
||||||
|
allowAmbiguousChars = false,
|
||||||
length = 64,
|
length = 64,
|
||||||
alphabet,
|
alphabet,
|
||||||
}: {
|
}: {
|
||||||
withUppercase?: boolean
|
withUppercase?: boolean;
|
||||||
withLowercase?: boolean
|
withLowercase?: boolean;
|
||||||
withNumbers?: boolean
|
withNumbers?: boolean;
|
||||||
withHexaNumbers?: boolean
|
withHexaNumbers?: boolean;
|
||||||
withSymbols?: boolean
|
withSymbols?: boolean;
|
||||||
deniedChars?: string
|
deniedChars?: string;
|
||||||
length?: number
|
allowAmbiguousChars?: boolean;
|
||||||
alphabet?: string
|
length?: number;
|
||||||
|
alphabet?: string;
|
||||||
}) {
|
}) {
|
||||||
const allAlphabet = (alphabet ?? (
|
const allDeniedChars = deniedChars + (allowAmbiguousChars ? '' : 'Oo01lI'); // Deny visually similar characters if not allowed
|
||||||
(withUppercase ? 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' : '')
|
const allAlphabet = (
|
||||||
+ (withLowercase ? 'abcdefghijklmnopqrstuvwxyz' : '')
|
alphabet ??
|
||||||
+ (withNumbers ? '0123456789' : '')
|
(withUppercase ? 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' : '') +
|
||||||
+ (withHexaNumbers ? '0123456789abcdef' : '')
|
(withLowercase ? 'abcdefghijklmnopqrstuvwxyz' : '') +
|
||||||
+ (withSymbols ? '.,;:!?./-"\'#{([-|\\@)]=}*+' : '')
|
(withNumbers ? '0123456789' : '') +
|
||||||
)).split('').filter(c => !(deniedChars?.includes(c))).join('');
|
(withHexaNumbers ? '0123456789abcdef' : '') +
|
||||||
|
(withSymbols ? '.,;:!?./-"\'#{([-|\\@)]=}*+' : '')
|
||||||
|
)
|
||||||
|
.split('')
|
||||||
|
.filter((c) => !allDeniedChars?.includes(c))
|
||||||
|
.join('');
|
||||||
|
|
||||||
const len = length < 1 ? 1 : length;
|
const len = length < 1 ? 1 : length;
|
||||||
return shuffleString(allAlphabet.repeat(len)).substring(0, len);
|
return shuffleString(allAlphabet.repeat(len)).substring(0, len);
|
||||||
|
|||||||
@@ -6,23 +6,46 @@ import { computedRefreshable } from '@/composable/computedRefreshable';
|
|||||||
|
|
||||||
const count = useQueryParamOrStorage({ name: 'count', storageName: 'token-generator:count', defaultValue: 1 });
|
const count = useQueryParamOrStorage({ name: 'count', storageName: 'token-generator:count', defaultValue: 1 });
|
||||||
const length = useQueryParamOrStorage({ name: 'length', storageName: 'token-generator:length', defaultValue: 64 });
|
const length = useQueryParamOrStorage({ name: 'length', storageName: 'token-generator:length', defaultValue: 64 });
|
||||||
const withUppercase = useQueryParamOrStorage({ name: 'uppercase', storageName: 'token-generator:uppercase', defaultValue: true });
|
const withUppercase = useQueryParamOrStorage({
|
||||||
const withLowercase = useQueryParamOrStorage({ name: 'lowercase', storageName: 'token-generator:lowercase', defaultValue: true });
|
name: 'uppercase',
|
||||||
const withNumbers = useQueryParamOrStorage({ name: 'numbers', storageName: 'token-generator:numbers', defaultValue: true });
|
storageName: 'token-generator:uppercase',
|
||||||
const withSymbols = useQueryParamOrStorage({ name: 'symbols', storageName: 'token-generator:symbols', defaultValue: false });
|
defaultValue: true,
|
||||||
|
});
|
||||||
|
const withLowercase = useQueryParamOrStorage({
|
||||||
|
name: 'lowercase',
|
||||||
|
storageName: 'token-generator:lowercase',
|
||||||
|
defaultValue: true,
|
||||||
|
});
|
||||||
|
const withNumbers = useQueryParamOrStorage({
|
||||||
|
name: 'numbers',
|
||||||
|
storageName: 'token-generator:numbers',
|
||||||
|
defaultValue: true,
|
||||||
|
});
|
||||||
|
const withSymbols = useQueryParamOrStorage({
|
||||||
|
name: 'symbols',
|
||||||
|
storageName: 'token-generator:symbols',
|
||||||
|
defaultValue: false,
|
||||||
|
});
|
||||||
const deniedChars = useQueryParamOrStorage({ name: 'deny', storageName: 'token-generator:deny', defaultValue: '' });
|
const deniedChars = useQueryParamOrStorage({ name: 'deny', storageName: 'token-generator:deny', defaultValue: '' });
|
||||||
|
const allowAmbiguousChars = useQueryParamOrStorage({
|
||||||
|
name: 'allow',
|
||||||
|
storageName: 'token-generator:allow-ambiguous',
|
||||||
|
defaultValue: false,
|
||||||
|
});
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
const [tokens, refreshTokens] = computedRefreshable(() =>
|
const [tokens, refreshTokens] = computedRefreshable(() =>
|
||||||
Array.from({ length: count.value < 1 ? 1 : count.value },
|
Array.from({ length: count.value < 1 ? 1 : count.value }, () =>
|
||||||
() => createToken({
|
createToken({
|
||||||
length: length.value,
|
length: length.value,
|
||||||
withUppercase: withUppercase.value,
|
withUppercase: withUppercase.value,
|
||||||
withLowercase: withLowercase.value,
|
withLowercase: withLowercase.value,
|
||||||
withNumbers: withNumbers.value,
|
withNumbers: withNumbers.value,
|
||||||
withSymbols: withSymbols.value,
|
withSymbols: withSymbols.value,
|
||||||
|
allowAmbiguousChars: allowAmbiguousChars.value,
|
||||||
deniedChars: deniedChars.value,
|
deniedChars: deniedChars.value,
|
||||||
})).join('\n'),
|
}),
|
||||||
|
).join('\n'),
|
||||||
);
|
);
|
||||||
|
|
||||||
const { copy } = useCopy({ source: tokens, text: t('tools.token-generator.copied') });
|
const { copy } = useCopy({ source: tokens, text: t('tools.token-generator.copied') });
|
||||||
@@ -50,13 +73,20 @@ const { copy } = useCopy({ source: tokens, text: t('tools.token-generator.copied
|
|||||||
</n-space>
|
</n-space>
|
||||||
</n-form>
|
</n-form>
|
||||||
|
|
||||||
<n-form-item :label="t('tools.token-generator.texts.label-denied-characters-ie-visually-similar-oo01li-or-punctuations')" label-placement="top">
|
<n-form-item
|
||||||
|
:label="t('tools.token-generator.texts.label-denied-characters-ie-visually-similar-oo01li-or-punctuations')"
|
||||||
|
label-placement="top"
|
||||||
|
>
|
||||||
<c-input-text
|
<c-input-text
|
||||||
v-model:value="deniedChars"
|
v-model:value="deniedChars"
|
||||||
:placeholder="t('tools.token-generator.texts.placeholder-put-characters-to-deny-from-token')"
|
:placeholder="t('tools.token-generator.texts.placeholder-put-characters-to-deny-from-token')"
|
||||||
/>
|
/>
|
||||||
</n-form-item>
|
</n-form-item>
|
||||||
|
|
||||||
|
<n-form-item :label="t('tools.token-generator.texts.label-allow-ambiguous-characters')" label-placement="left">
|
||||||
|
<n-switch v-model:value="allowAmbiguousChars" />
|
||||||
|
</n-form-item>
|
||||||
|
|
||||||
<n-form-item :label="`${t('tools.token-generator.length')} (${length})`" label-placement="left">
|
<n-form-item :label="`${t('tools.token-generator.length')} (${length})`" label-placement="left">
|
||||||
<n-slider v-model:value="length" :step="1" :min="1" :max="512" mr-2 />
|
<n-slider v-model:value="length" :step="1" :min="1" :max="512" mr-2 />
|
||||||
<n-input-number-i18n v-model:value="length" :min="1" :max="512" size="small" />
|
<n-input-number-i18n v-model:value="length" :min="1" :max="512" size="small" />
|
||||||
|
|||||||
Reference in new issue
Block a user