From dfd056ec8f0df7901adbeaa3e0cc99a58c551b4d Mon Sep 17 00:00:00 2001
From: Jens Christian Aanestad <jenscaa@stud.ntnu.no>
Date: Fri, 19 Apr 2024 10:51:39 +0200
Subject: [PATCH] refactor/fixed password validation

---
 src/components/InputFields/BaseInput.vue | 5 +++++
 src/components/Login/LoginForm.vue       | 2 +-
 src/components/SignUp/SignUpForm.vue     | 8 ++++++++
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/components/InputFields/BaseInput.vue b/src/components/InputFields/BaseInput.vue
index 28f6f3e..22ed034 100644
--- a/src/components/InputFields/BaseInput.vue
+++ b/src/components/InputFields/BaseInput.vue
@@ -29,6 +29,10 @@ const props = defineProps({
   min: {
     type: String,
     required: false
+  },
+  pattern: {
+    type: String,
+    default: null
   }
 });
 
@@ -47,6 +51,7 @@ const onInputEvent = (event: any) => {
            :placeholder="props.placeholder"
            :id="inputId" required
            :min="min"
+           :pattern="pattern"
     />
     <div v-if="props.isValid" class="invalid-feedback">Invalid {{ label }}</div>
     <div v-else class="valid-feedback">Valid {{ label }}</div>
diff --git a/src/components/Login/LoginForm.vue b/src/components/Login/LoginForm.vue
index 2f0a5f7..2354d6e 100644
--- a/src/components/Login/LoginForm.vue
+++ b/src/components/Login/LoginForm.vue
@@ -62,7 +62,7 @@ const handleSubmit = async () => {
     <form ref="formRef" id="loginForm" @submit.prevent="handleSubmit" novalidate>
       <BaseInput :model-value="emailRef" @input-change-event="handleEmailInputEvent" id="emailInput" input-id="email"
         type="email" label="Email" placeholder="Enter your email" />
-      <BaseInput :model-value="passwordRef" @input-change-event="handlePasswordInputEvent" id="passwordInput"
+      <BaseInput pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,16}" :model-value="passwordRef" @input-change-event="handlePasswordInputEvent" id="passwordInput"
         input-id="password" type="password" label="Password" placeholder="Enter password" />
       <p class="text-danger">{{ errorMsg }}</p>
       <button1 id="confirmButton" type="submit" @click="handleSubmit" button-text="Login"></button1>
diff --git a/src/components/SignUp/SignUpForm.vue b/src/components/SignUp/SignUpForm.vue
index 5ee2367..b085f6e 100644
--- a/src/components/SignUp/SignUpForm.vue
+++ b/src/components/SignUp/SignUpForm.vue
@@ -33,6 +33,14 @@ const handleConfirmPasswordInputEvent = (newValue: any) => {
 }
 
 const handleSubmit = () => {
+  const form = formRef.value;
+
+  // Check if the form is valid
+  if (form.checkValidity()) {
+    // Form is valid, submit the form or perform other actions
+    console.log('Form is valid');
+  }
+
   formRef.value.classList.add("was-validated")
 }
 
-- 
GitLab