passphrase validation

This commit is contained in:
2023-05-25 20:29:24 +02:00
parent 1ab3db6cce
commit 5a4bba2dcd
2 changed files with 20 additions and 9 deletions

View File

@@ -37,14 +37,12 @@ watch(
) )
const passphrase = ref('') const passphrase = ref('')
const passphraseValid = ref<boolean>()
const submitPassphrase = (close: () => void) => { const submitPassphrase = (close: () => void) => {
const passphraseValid = setClientKey(passphrase.value) const setClientKeyResult = setClientKey(passphrase.value)
if (!passphraseValid) { passphraseValid.value = setClientKeyResult
console.log('passphrase is invalid') if (passphraseValid.value) close()
} else {
close()
}
} }
const loading = computed(() => notes.value.length === 0 || passphraseRequired.value) const loading = computed(() => notes.value.length === 0 || passphraseRequired.value)
@@ -138,12 +136,25 @@ provide('loading', loading)
</div> </div>
<Modal :open="passphraseRequired" :persistent="true"> <Modal :open="passphraseRequired" :persistent="true">
<template #title>Enter your passphrase</template> <template #title>Enter your passphrase</template>
<template #default> <template #default="{ close }">
<p> <p>
Your notes are encrypted. Please enter your encryption key passphrase to decrypt your cloud Your notes are encrypted. Please enter your encryption key passphrase to decrypt your cloud
notes. notes.
</p> </p>
<input type="password" class="input-bordered input mt-4 w-full" v-model="passphrase" /> <form @submit.prevent="submitPassphrase(close)">
<input
type="password"
class="input-bordered input mt-4 w-full"
:class="passphraseValid === false && 'input-error'"
v-model="passphrase"
/>
</form>
<div class="alert alert-error mt-4 flex-row" v-if="passphraseValid === false">
<div>
<i class="fa-solid fa-triangle-exclamation"></i>
The passphrase you entered is incorrect.
</div>
</div>
</template> </template>
<template #actions="{ close }"> <template #actions="{ close }">
<button class="btn-primary btn-sm btn" @click="submitPassphrase(close)">Submit</button> <button class="btn-primary btn-sm btn" @click="submitPassphrase(close)">Submit</button>

View File

@@ -21,7 +21,7 @@ export const getClientKey = () => {
export const setClientKey = (passphrase: string) => { export const setClientKey = (passphrase: string) => {
const calculatedClientKey = calculateClientKey(passphrase) const calculatedClientKey = calculateClientKey(passphrase)
const verified = verifyClientKey(calculatedClientKey) const verified = verifyClientKey(calculatedClientKey)
if (!user.value || !verified) return if (!user.value || !verified) return false
const clientKeys = getClientKeysFromLocalStorage() const clientKeys = getClientKeysFromLocalStorage()
clientKeys[user.value.uid] = calculatedClientKey clientKeys[user.value.uid] = calculatedClientKey
localStorage.setItem('clientKeys', JSON.stringify(clientKeys)) localStorage.setItem('clientKeys', JSON.stringify(clientKeys))