mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
1 parent
e20b284fba
commit
603140a25d
4 files changed
+85
No files matched your search
@@ -0,0 +1,10 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { getSecretKey } from './django-secret-generator.service';
|
||||
|
||||
describe('django-secret-generato', () => {
|
||||
describe('getSecretKey', () => {
|
||||
it('should return a value between 50 and 60 chars', () => {
|
||||
expect(getSecretKey()).toMatch(/[abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)]{50,60}/);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
const RAND_MAX = 2 ** 8;
|
||||
|
||||
const CHARS = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'.split('');
|
||||
|
||||
export function generateRandomValue(min: number, max: number): number {
|
||||
const generatorMax = max - min;
|
||||
if (generatorMax > RAND_MAX) {
|
||||
throw new Error('Generating range is too large');
|
||||
}
|
||||
|
||||
let randomValue: number;
|
||||
do {
|
||||
randomValue = window.crypto.getRandomValues(new Uint8Array(1))[0];
|
||||
} while (randomValue > generatorMax);
|
||||
|
||||
return min + randomValue;
|
||||
}
|
||||
|
||||
export function getSecretKey() {
|
||||
const keyLength = generateRandomValue(50, 60);
|
||||
|
||||
const key = [];
|
||||
for (let i = 0; i < keyLength; i++) {
|
||||
const index = generateRandomValue(0, CHARS.length - 1);
|
||||
key.push(CHARS[index]);
|
||||
}
|
||||
return key.join('');
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<script setup lang="ts">
|
||||
import { getSecretKey } from './django-secret-generator.service';
|
||||
import { useCopy } from '@/composable/copy';
|
||||
import { computedRefreshable } from '@/composable/computedRefreshable';
|
||||
|
||||
const [tokens, refreshTokens] = computedRefreshable(() =>
|
||||
getSecretKey(),
|
||||
);
|
||||
|
||||
const { copy } = useCopy({ source: tokens, text: 'Django secret key copied to clipboard' });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-card>
|
||||
<c-input-text
|
||||
v-model:value="tokens"
|
||||
label="Django secret key:"
|
||||
label-position="left"
|
||||
readonly
|
||||
class="token-display"
|
||||
/>
|
||||
|
||||
<div mt-5 flex justify-center gap-3>
|
||||
<c-button @click="copy()">
|
||||
Copy
|
||||
</c-button>
|
||||
<c-button @click="refreshTokens">
|
||||
Regenerate
|
||||
</c-button>
|
||||
</div>
|
||||
</c-card>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,13 @@
|
||||
import { BrandPython } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Django Secret Generator',
|
||||
path: '/django-secret-generator',
|
||||
description: 'Generate a Django secret key',
|
||||
keywords: ['django', 'secret', 'generator'],
|
||||
component: () => import('./django-secret-generator.vue'),
|
||||
icon: BrandPython,
|
||||
createdAt: new Date('2025-08-17'),
|
||||
category: 'Development',
|
||||
});
|
||||
Reference in new issue
Block a user