From ac9d530325f5f3eb1b335cc94c9aa9574b309c9d Mon Sep 17 00:00:00 2001 From: Michael Wedl Date: Mon, 16 Dec 2024 07:09:52 +0100 Subject: [PATCH] Add button to generate random password to password fields --- CHANGELOG.md | 1 + .../frontend/src/components/LoginForm.vue | 2 +- .../src/components/Notes/ShareInfoForm.vue | 1 + .../pages/projects/[projectId]/publish.vue | 12 ++--- .../pages/users/[userId]/reset-password.vue | 2 +- packages/frontend/src/pages/users/new.vue | 2 +- .../src/pages/users/self/security.vue | 2 +- .../src/components/S/PasswordField.vue | 45 +++++++++++++------ packages/nuxt-base-layer/src/utils/helpers.ts | 8 +++- 9 files changed, 48 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07105480c..a5f7390e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Update and optimize designs: demo, HTB and OffSec designs * Add design for HTB CAPE certification * Warn about relative URLs in PDFs during rendering +* Add button to generate random password to password fields ## v2024.96 - 2024-12-04 diff --git a/packages/frontend/src/components/LoginForm.vue b/packages/frontend/src/components/LoginForm.vue index 1e54557c8..8211d77da 100644 --- a/packages/frontend/src/components/LoginForm.vue +++ b/packages/frontend/src/components/LoginForm.vue @@ -136,7 +136,7 @@ diff --git a/packages/frontend/src/components/Notes/ShareInfoForm.vue b/packages/frontend/src/components/Notes/ShareInfoForm.vue index 6dae7d7c2..466c52812 100644 --- a/packages/frontend/src/components/Notes/ShareInfoForm.vue +++ b/packages/frontend/src/components/Notes/ShareInfoForm.vue @@ -29,6 +29,7 @@ :model-value="modelValue.password" @update:model-value="updateProp('password', $event)" label="Password (optional)" + generate :disabled="props.disabled" :error-messages="props.error?.password" /> diff --git a/packages/frontend/src/pages/projects/[projectId]/publish.vue b/packages/frontend/src/pages/projects/[projectId]/publish.vue index e6f07a706..73caaee12 100644 --- a/packages/frontend/src/pages/projects/[projectId]/publish.vue +++ b/packages/frontend/src/pages/projects/[projectId]/publish.vue @@ -47,7 +47,7 @@ v-model="form.password" :error-messages="(localSettings.encryptPdfEnabled && form.password.length === 0) ? ['Password required'] : []" label="PDF password" - append-inner-icon="mdi-lock-reset" @click:append-inner="form.password = generateNewPassword()" + append-inner-icon="mdi-lock-reset" @click:append-inner="form.password = generateRandomPassword()" spellcheck="false" class="mt-4" /> @@ -106,8 +106,7 @@ diff --git a/packages/nuxt-base-layer/src/utils/helpers.ts b/packages/nuxt-base-layer/src/utils/helpers.ts index caf62bcd7..95b0f4820 100644 --- a/packages/nuxt-base-layer/src/utils/helpers.ts +++ b/packages/nuxt-base-layer/src/utils/helpers.ts @@ -1,4 +1,4 @@ -import { setWith, clone, cloneDeep } from "lodash-es"; +import { setWith, clone, cloneDeep, sampleSize } from "lodash-es"; export { decode as base64decode, encode as base64encode } from 'base64-arraybuffer'; export { default as fileDownload } from 'js-file-download'; export { default as urlJoin } from 'url-join'; @@ -180,3 +180,9 @@ export function useAbortController(performFetch: (fetchOptions: { signal: Abo pending, } } + +export function generateRandomPassword() { + // Charset does not contain similar-looking characters and numbers; removed: 0,O, 1,l,I + const charset = '23456789' + 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ' + '!#%&+-_'; + return sampleSize(charset, 20).join(''); +}