-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #257 from sunnydanu/feat(new-tool)--argon2-passwor…
…d-hashing-and-verification feat(new-tool):-argon2-password-hashing-and-verification
- Loading branch information
Showing
8 changed files
with
232 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
src/tools/argon2-hash-generator/argon2-hash-generator.e2e.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { expect, test } from '@playwright/test'; | ||
|
||
test.describe('Tool - Argon2 hash generator', () => { | ||
test.beforeEach(async ({ page }) => { | ||
await page.goto('/argon2-hash-generator'); | ||
}); | ||
|
||
test('Has correct title', async ({ page }) => { | ||
await expect(page).toHaveTitle('GoDev.Run - Argon2 hash generator'); | ||
}); | ||
|
||
test('hash a string a verify that the result match', async ({ page }) => { | ||
await page.getByTestId('input').fill('azerty'); | ||
|
||
await new Promise(resolve => setTimeout(resolve, 500)); | ||
const hash = await page.getByTestId('hash').inputValue(); | ||
|
||
await page.getByTestId('compare-string').fill('azerty'); | ||
await page.getByTestId('compare-hash').fill(hash); | ||
|
||
await new Promise(resolve => setTimeout(resolve, 500)); | ||
const doTheyMatch = await page.getByTestId('do-they-match').innerText(); | ||
|
||
expect(doTheyMatch.trim()).toEqual('Yes'); | ||
}); | ||
|
||
test('hash a string a verify that the does not result match another string', async ({ page }) => { | ||
await page.getByTestId('input').fill('azerty'); | ||
const hash = await page.getByTestId('hash').inputValue(); | ||
|
||
await page.getByTestId('compare-string').fill('NOT AZERTY'); | ||
await page.getByTestId('compare-hash').fill(hash); | ||
const doTheyMatch = await page.getByTestId('do-they-match').innerText(); | ||
|
||
expect(doTheyMatch.trim()).toEqual('No'); | ||
}); | ||
}); |
109 changes: 109 additions & 0 deletions
109
src/tools/argon2-hash-generator/argon2-hash-generator.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<script setup lang="ts"> | ||
import { argon2Verify, argon2id } from 'hash-wasm'; | ||
import { useCopy } from '@/composable/copy'; | ||
const input = ref(''); | ||
const iterations = ref(32); | ||
const memorySize = ref(512); | ||
const hashLength = ref(32); | ||
const hashed = computedAsync( | ||
async () => | ||
argon2id({ | ||
password: input.value, | ||
salt: window.crypto.getRandomValues(new Uint8Array(16)), | ||
parallelism: 1, | ||
iterations: iterations.value, | ||
memorySize: memorySize.value, | ||
hashLength: hashLength.value, | ||
outputType: 'encoded', | ||
}), | ||
'', | ||
); | ||
const { copy } = useCopy({ source: hashed, text: 'Hashed string copied to the clipboard' }); | ||
const compareString = ref(''); | ||
const compareHash = ref(''); | ||
const compareMatch = computedAsync( | ||
() => argon2Verify({ password: compareString.value, hash: compareHash.value }), | ||
false, | ||
); | ||
</script> | ||
|
||
<template> | ||
<n-card title="Hash"> | ||
<n-form label-width="120"> | ||
<n-form-item label="Your string: " label-placement="left"> | ||
<n-input | ||
v-model:value="input" | ||
placeholder="Your string to bcrypt..." | ||
autocomplete="off" | ||
autocorrect="off" | ||
autocapitalize="off" | ||
spellcheck="false" | ||
:input-props="{ | ||
'data-test-id': 'input', | ||
}" | ||
/> | ||
</n-form-item> | ||
<n-form-item label="Iteration: " label-placement="left"> | ||
<n-input-number v-model:value="iterations" placeholder="Iterations..." min="0" w-full /> | ||
</n-form-item> | ||
<n-form-item label="Memory size: " label-placement="left"> | ||
<n-input-number v-model:value="memorySize" placeholder="Memory size..." min="0" w-full /> | ||
</n-form-item> | ||
<n-input | ||
:value="hashed" | ||
readonly | ||
style="text-align: center" | ||
placeholder="Set a string to hash above..." | ||
:input-props="{ | ||
'data-test-id': 'hash', | ||
}" | ||
/> | ||
</n-form> | ||
<br> | ||
<n-space justify="center"> | ||
<n-button secondary @click="copy"> | ||
Copy hash | ||
</n-button> | ||
</n-space> | ||
</n-card> | ||
|
||
<n-card title="Compare string with hash"> | ||
<n-form label-width="120"> | ||
<n-form-item label="Your string: " label-placement="left"> | ||
<n-input | ||
v-model:value="compareString" | ||
placeholder="Your string to compare..." | ||
autocomplete="off" | ||
autocorrect="off" | ||
autocapitalize="off" | ||
spellcheck="false" | ||
:input-props="{ | ||
'data-test-id': 'compare-string', | ||
}" | ||
/> | ||
</n-form-item> | ||
<n-form-item label="Your hash: " label-placement="left"> | ||
<n-input | ||
v-model:value="compareHash" | ||
placeholder="Your hash to compare..." | ||
autocomplete="off" | ||
autocorrect="off" | ||
autocapitalize="off" | ||
spellcheck="false" | ||
:input-props="{ | ||
'data-test-id': 'compare-hash', | ||
}" | ||
/> | ||
</n-form-item> | ||
<n-form-item label="Do they match ? " label-placement="left" :show-feedback="false"> | ||
<span data-test-id="do-they-match"> | ||
<n-tag v-if="compareMatch" :bordered="false" type="success" round>Yes</n-tag> | ||
<n-tag v-else :bordered="false" type="error" round>No</n-tag> | ||
</span> | ||
</n-form-item> | ||
</n-form> | ||
</n-card> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Lock } from '@vicons/tabler'; | ||
import { defineTool } from '../tool'; | ||
|
||
export const tool = defineTool({ | ||
name: 'Argon2 hash generator', | ||
path: '/argon2-hash-generator', | ||
description: 'Hash and compare string (password) using Argon2', | ||
keywords: ['argon2', 'hash', 'generator', 'password', 'salt', 'crypto', 'security'], | ||
component: () => import('./argon2-hash-generator.vue'), | ||
icon: Lock, | ||
createdAt: new Date('2023-04-16'), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters