From 820ec33f7d6e9f1d8292ca38f37ab3dccf27360b Mon Sep 17 00:00:00 2001 From: CyberSphinxxx Date: Thu, 14 Nov 2024 01:30:10 +0800 Subject: [PATCH] minor adjustments --- .../password_manage_save.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/password_manager/password_manager_save/password_manage_save.js b/password_manager/password_manager_save/password_manage_save.js index b3ade29..daefc4c 100644 --- a/password_manager/password_manager_save/password_manage_save.js +++ b/password_manager/password_manager_save/password_manage_save.js @@ -56,10 +56,20 @@ async function encryptData(data) { form.addEventListener('submit', async function(e) { e.preventDefault(); + const password = passwordInput.value; // Get the password input value + const strength = evaluatePasswordStrength(password); // Evaluate password strength + + // Only save if the password is strong enough + if (strength === 'Weak') { + errorMessage.textContent = 'Password is too weak. Please choose a stronger password.'; + errorMessage.style.display = 'block'; + return; + } + const passwordData = { label: document.getElementById('label').value, username: document.getElementById('username').value, - password: document.getElementById('password').value, + password: password, dateAdded: new Date().toISOString() }; @@ -91,7 +101,7 @@ form.addEventListener('submit', async function(e) { errorMessage.style.display = 'none'; setTimeout(() => { clearForm(); - }, 2000) + }, 2000); } catch (error) { errorMessage.textContent = 'Error saving password: ' + error.message; errorMessage.style.display = 'block'; @@ -99,11 +109,9 @@ form.addEventListener('submit', async function(e) { } }); -// Clear form function -function clearForm() { +// Clear form function clearForm() { document.getElementById('label').value = ''; document.getElementById('username').value = ''; document.getElementById('password').value = ''; strengthIndicator.textContent = ''; errorMessage.style.display = 'none'; -} \ No newline at end of file