2022-04-18 10:16:59 +02:00
|
|
|
<template>
|
|
|
|
<n-card title="Hash">
|
|
|
|
<n-form label-width="120">
|
2022-04-22 23:31:40 +02:00
|
|
|
<n-form-item label="Your string: " label-placement="left">
|
2022-04-18 10:16:59 +02:00
|
|
|
<n-input
|
|
|
|
v-model:value="input"
|
|
|
|
placeholder="Your string to bcrypt..."
|
|
|
|
autocomplete="off"
|
|
|
|
autocorrect="off"
|
|
|
|
autocapitalize="off"
|
|
|
|
spellcheck="false"
|
|
|
|
/>
|
|
|
|
</n-form-item>
|
2022-04-22 23:31:40 +02:00
|
|
|
<n-form-item label="Salt count: " label-placement="left">
|
2023-04-06 19:36:30 +02:00
|
|
|
<n-input-number v-model:value="saltCount" placeholder="Salt rounds..." :max="10" :min="0" w-full />
|
2022-04-18 10:16:59 +02:00
|
|
|
</n-form-item>
|
2022-04-22 23:31:40 +02:00
|
|
|
<n-input :value="hashed" readonly style="text-align: center" />
|
2022-04-18 10:16:59 +02:00
|
|
|
</n-form>
|
2022-04-22 23:31:40 +02:00
|
|
|
<br />
|
2022-04-18 10:16:59 +02:00
|
|
|
<n-space justify="center">
|
2022-04-22 23:31:40 +02:00
|
|
|
<n-button secondary @click="copy"> Copy hash </n-button>
|
2022-04-18 10:16:59 +02:00
|
|
|
</n-space>
|
|
|
|
</n-card>
|
|
|
|
|
|
|
|
<n-card title="Compare string with hash">
|
|
|
|
<n-form label-width="120">
|
2022-04-22 23:31:40 +02:00
|
|
|
<n-form-item label="Your string: " label-placement="left">
|
2022-04-18 10:16:59 +02:00
|
|
|
<n-input
|
|
|
|
v-model:value="compareString"
|
|
|
|
placeholder="Your string to compare..."
|
|
|
|
autocomplete="off"
|
|
|
|
autocorrect="off"
|
|
|
|
autocapitalize="off"
|
|
|
|
spellcheck="false"
|
|
|
|
/>
|
|
|
|
</n-form-item>
|
2022-04-22 23:31:40 +02:00
|
|
|
<n-form-item label="Your hash: " label-placement="left">
|
2022-04-18 10:16:59 +02:00
|
|
|
<n-input
|
|
|
|
v-model:value="compareHash"
|
|
|
|
placeholder="Your hahs to compare..."
|
|
|
|
autocomplete="off"
|
|
|
|
autocorrect="off"
|
|
|
|
autocapitalize="off"
|
|
|
|
spellcheck="false"
|
|
|
|
/>
|
|
|
|
</n-form-item>
|
2022-04-22 23:31:40 +02:00
|
|
|
<n-form-item label="Do they match ? " label-placement="left" :show-feedback="false">
|
|
|
|
<div class="compare-result" :class="{ positive: compareMatch }">
|
2022-04-18 10:16:59 +02:00
|
|
|
{{ compareMatch ? 'Yes' : 'No' }}
|
|
|
|
</div>
|
|
|
|
</n-form-item>
|
|
|
|
</n-form>
|
|
|
|
</n-card>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
import { computed, ref } from 'vue';
|
2022-04-22 23:31:40 +02:00
|
|
|
import { hashSync, compareSync } from 'bcryptjs';
|
2022-04-18 10:16:59 +02:00
|
|
|
import { useCopy } from '@/composable/copy';
|
|
|
|
import { useThemeVars } from 'naive-ui';
|
|
|
|
|
2022-04-22 23:31:40 +02:00
|
|
|
const themeVars = useThemeVars();
|
2022-04-18 10:16:59 +02:00
|
|
|
|
2022-04-22 23:31:40 +02:00
|
|
|
const input = ref('');
|
|
|
|
const saltCount = ref(10);
|
|
|
|
const hashed = computed(() => hashSync(input.value, saltCount.value));
|
|
|
|
const { copy } = useCopy({ source: hashed, text: 'Hashed string copied to the clipboard' });
|
2022-04-18 10:16:59 +02:00
|
|
|
|
2022-04-22 23:31:40 +02:00
|
|
|
const compareString = ref('');
|
|
|
|
const compareHash = ref('');
|
|
|
|
const compareMatch = computed(() => compareSync(compareString.value, compareHash.value));
|
2022-04-18 10:16:59 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="less" scoped>
|
|
|
|
.compare-result {
|
2022-04-22 23:31:40 +02:00
|
|
|
color: v-bind('themeVars.errorColor');
|
2022-04-18 10:16:59 +02:00
|
|
|
|
|
|
|
&.positive {
|
2022-04-22 23:31:40 +02:00
|
|
|
color: v-bind('themeVars.successColor');
|
2022-04-18 10:16:59 +02:00
|
|
|
}
|
|
|
|
}
|
2022-04-22 23:31:40 +02:00
|
|
|
</style>
|