2023-05-28 23:13:24 +02:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { compareSync, hashSync } from 'bcryptjs';
|
|
|
|
import { useThemeVars } from 'naive-ui';
|
|
|
|
import { useCopy } from '@/composable/copy';
|
|
|
|
|
|
|
|
const themeVars = useThemeVars();
|
|
|
|
|
|
|
|
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' });
|
|
|
|
|
|
|
|
const compareString = ref('');
|
|
|
|
const compareHash = ref('');
|
|
|
|
const compareMatch = computed(() => compareSync(compareString.value, compareHash.value));
|
|
|
|
</script>
|
|
|
|
|
2022-04-18 10:16:59 +02:00
|
|
|
<template>
|
2023-04-20 20:49:28 +02:00
|
|
|
<c-card title="Hash">
|
2023-05-14 21:26:18 +02:00
|
|
|
<c-input-text
|
|
|
|
v-model:value="input"
|
|
|
|
placeholder="Your string to bcrypt..."
|
|
|
|
raw-text
|
|
|
|
label="Your string: "
|
|
|
|
label-position="left"
|
|
|
|
label-width="120px"
|
|
|
|
mb-2
|
|
|
|
/>
|
|
|
|
<n-form-item label="Salt count: " label-placement="left" label-width="120">
|
|
|
|
<n-input-number v-model:value="saltCount" placeholder="Salt rounds..." :max="10" :min="0" w-full />
|
|
|
|
</n-form-item>
|
|
|
|
|
|
|
|
<c-input-text :value="hashed" readonly text-center />
|
|
|
|
|
2023-05-27 17:36:15 +02:00
|
|
|
<div mt-5 flex justify-center>
|
2023-08-10 00:07:44 +02:00
|
|
|
<c-button @click="copy()">
|
2023-05-28 23:13:24 +02:00
|
|
|
Copy hash
|
|
|
|
</c-button>
|
2023-05-27 17:36:15 +02:00
|
|
|
</div>
|
2023-04-20 20:49:28 +02:00
|
|
|
</c-card>
|
2022-04-18 10:16:59 +02:00
|
|
|
|
2023-04-20 20:49:28 +02:00
|
|
|
<c-card title="Compare string with hash">
|
2022-04-18 10:16:59 +02:00
|
|
|
<n-form label-width="120">
|
2022-04-22 23:31:40 +02:00
|
|
|
<n-form-item label="Your string: " label-placement="left">
|
2023-05-14 21:26:18 +02:00
|
|
|
<c-input-text v-model:value="compareString" placeholder="Your string to compare..." raw-text />
|
2022-04-18 10:16:59 +02:00
|
|
|
</n-form-item>
|
2022-04-22 23:31:40 +02:00
|
|
|
<n-form-item label="Your hash: " label-placement="left">
|
2023-09-01 16:30:51 +02:00
|
|
|
<c-input-text v-model:value="compareHash" placeholder="Your hash to compare..." raw-text />
|
2022-04-18 10:16:59 +02:00
|
|
|
</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>
|
2023-04-20 20:49:28 +02:00
|
|
|
</c-card>
|
2022-04-18 10:16:59 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<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>
|