it-tools/tools/crypto/token-generator.vue

85 lines
2.3 KiB
Vue
Raw Normal View History

2021-02-06 11:14:28 +01:00
<template>
2021-05-28 19:44:27 +02:00
<ToolWrapper :config="$toolConfig">
2021-02-06 11:14:28 +01:00
<v-row no-gutters>
<v-col lg="6" md="12">
2021-06-01 00:09:33 +02:00
<v-switch v-model="config.withLowercase" label="Lowercase (abc...)" />
<v-switch v-model="config.withUppercase" label="Uppercase (ABC...)" />
2021-02-06 11:14:28 +01:00
</v-col>
<v-col lg="6" md="12">
2021-06-01 00:09:33 +02:00
<v-switch v-model="config.withNumbers" label="Numbers (123...)" />
<v-switch v-model="config.withSpecials" label="Specials (#]-...)" />
2021-02-06 11:14:28 +01:00
</v-col>
</v-row>
2021-06-01 00:09:33 +02:00
<v-slider v-model="config.length" :label="`Length (${config.length})`" min="1" max="512" />
2021-02-06 11:14:28 +01:00
2021-06-01 00:09:33 +02:00
<v-textarea v-model="token" outlined />
2021-02-06 11:14:28 +01:00
<div class="text-center">
<v-btn depressed class="mr-4" @click="refreshToken()">
Refresh
</v-btn>
2021-02-13 19:55:45 +01:00
<v-btn depressed @click="copy(token)">
Copy token
</v-btn>
2021-02-06 11:14:28 +01:00
</div>
</ToolWrapper>
</template>
2021-05-28 19:44:27 +02:00
<tool>
title: 'Token generator'
description: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Delectus distinctio dolor dolorum eaque eligendi, facilis impedit laboriosam odit placeat.'
icon: 'mdi-key-chain-variant'
2021-06-01 00:07:04 +02:00
keywords: [ 'token', 'random', 'string', 'alphanumeric', 'symbols' ]
2021-05-28 19:44:27 +02:00
path: '/token-generator'
</tool>
2021-02-06 11:14:28 +01:00
<script lang="ts">
2021-06-01 00:07:04 +02:00
import {Component, Watch} from 'nuxt-property-decorator'
2021-02-13 19:55:45 +01:00
import Tool from '~/components/Tool.vue'
2021-03-14 20:11:39 +01:00
import {CopyableMixin} from '~/mixins/copyable.mixin'
import {shuffleString} from '~/utils/random'
2021-02-06 11:14:28 +01:00
const lowercase = 'abcdefghijklmopqrstuvwxyz'
const uppercase = 'ABCDEFGHIJKLMOPQRSTUVWXYZ'
const numbers = '0123456789'
const specials = '.,;:!?./-"\'#{([-|\\@)]=}*+'
2021-02-13 19:55:45 +01:00
@Component({
2021-03-14 20:11:39 +01:00
mixins: [CopyableMixin]
2021-02-13 19:55:45 +01:00
})
2021-02-06 11:14:28 +01:00
export default class TokenGenerator extends Tool {
2021-06-01 00:07:04 +02:00
token = '';
config = {
withNumbers: true,
withLowercase: true,
withUppercase: true,
withSpecials: false,
length: 64
2021-02-06 11:14:28 +01:00
}
2021-06-01 00:07:04 +02:00
created() {
this.refreshToken()
}
2021-02-06 11:14:28 +01:00
2021-06-01 00:07:04 +02:00
@Watch('config', {deep: true})
refreshToken() {
2021-02-06 11:14:28 +01:00
let result = ''
2021-06-01 00:07:04 +02:00
if (this.config.withLowercase) {
2021-02-06 11:14:28 +01:00
result += lowercase
}
2021-06-01 00:07:04 +02:00
if (this.config.withUppercase) {
2021-02-06 11:14:28 +01:00
result += uppercase
}
2021-06-01 00:07:04 +02:00
if (this.config.withNumbers) {
2021-02-06 11:14:28 +01:00
result += numbers
}
2021-06-01 00:07:04 +02:00
if (this.config.withSpecials) {
2021-02-06 11:14:28 +01:00
result += specials
}
this.token = shuffleString(result.repeat(this.config.length)).substring(0, this.config.length)
2021-02-06 11:14:28 +01:00
}
}
</script>