mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +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)
|
||||
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-allow-ambiguous-characters: Allows Visually Ambigous Characters
|
||||
percentage-calculator:
|
||||
title: Percentage calculator
|
||||
description: >-
|
||||
|
||||
@@ -7,25 +7,32 @@ export function createToken({
|
||||
withHexaNumbers = false,
|
||||
withSymbols = false,
|
||||
deniedChars = '',
|
||||
allowAmbiguousChars = false,
|
||||
length = 64,
|
||||
alphabet,
|
||||
}: {
|
||||
withUppercase?: boolean
|
||||
withLowercase?: boolean
|
||||
withNumbers?: boolean
|
||||
withHexaNumbers?: boolean
|
||||
withSymbols?: boolean
|
||||
deniedChars?: string
|
||||
length?: number
|
||||
alphabet?: string
|
||||
withUppercase?: boolean;
|
||||
withLowercase?: boolean;
|
||||
withNumbers?: boolean;
|
||||
withHexaNumbers?: boolean;
|
||||
withSymbols?: boolean;
|
||||
deniedChars?: string;
|
||||
allowAmbiguousChars?: boolean;
|
||||
length?: number;
|
||||
alphabet?: string;
|
||||
}) {
|
||||
const allAlphabet = (alphabet ?? (
|
||||
(withUppercase ? 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' : '')
|
||||
+ (withLowercase ? 'abcdefghijklmnopqrstuvwxyz' : '')
|
||||
+ (withNumbers ? '0123456789' : '')
|
||||
+ (withHexaNumbers ? '0123456789abcdef' : '')
|
||||
+ (withSymbols ? '.,;:!?./-"\'#{([-|\\@)]=}*+' : '')
|
||||
)).split('').filter(c => !(deniedChars?.includes(c))).join('');
|
||||
const allDeniedChars = deniedChars + (allowAmbiguousChars ? '' : 'Oo01lI'); // Deny visually similar characters if not allowed
|
||||
const allAlphabet = (
|
||||
alphabet ??
|
||||
(withUppercase ? 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' : '') +
|
||||
(withLowercase ? 'abcdefghijklmnopqrstuvwxyz' : '') +
|
||||
(withNumbers ? '0123456789' : '') +
|
||||
(withHexaNumbers ? '0123456789abcdef' : '') +
|
||||
(withSymbols ? '.,;:!?./-"\'#{([-|\\@)]=}*+' : '')
|
||||
)
|
||||
.split('')
|
||||
.filter((c) => !allDeniedChars?.includes(c))
|
||||
.join('');
|
||||
|
||||
const len = length < 1 ? 1 : length;
|
||||
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 length = useQueryParamOrStorage({ name: 'length', storageName: 'token-generator:length', defaultValue: 64 });
|
||||
const withUppercase = useQueryParamOrStorage({ name: 'uppercase', storageName: 'token-generator:uppercase', 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 withUppercase = useQueryParamOrStorage({
|
||||
name: 'uppercase',
|
||||
storageName: 'token-generator:uppercase',
|
||||
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 allowAmbiguousChars = useQueryParamOrStorage({
|
||||
name: 'allow',
|
||||
storageName: 'token-generator:allow-ambiguous',
|
||||
defaultValue: false,
|
||||
});
|
||||
const { t } = useI18n();
|
||||
|
||||
const [tokens, refreshTokens] = computedRefreshable(() =>
|
||||
Array.from({ length: count.value < 1 ? 1 : count.value },
|
||||
() => createToken({
|
||||
Array.from({ length: count.value < 1 ? 1 : count.value }, () =>
|
||||
createToken({
|
||||
length: length.value,
|
||||
withUppercase: withUppercase.value,
|
||||
withLowercase: withLowercase.value,
|
||||
withNumbers: withNumbers.value,
|
||||
withSymbols: withSymbols.value,
|
||||
allowAmbiguousChars: allowAmbiguousChars.value,
|
||||
deniedChars: deniedChars.value,
|
||||
})).join('\n'),
|
||||
}),
|
||||
).join('\n'),
|
||||
);
|
||||
|
||||
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-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
|
||||
v-model:value="deniedChars"
|
||||
:placeholder="t('tools.token-generator.texts.placeholder-put-characters-to-deny-from-token')"
|
||||
/>
|
||||
</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-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" />
|
||||
|
||||
Reference in new issue
Block a user