Skip to content

Commit

Permalink
Merge pull request #16 from kashikaga/main
Browse files Browse the repository at this point in the history
Added password validation
  • Loading branch information
sudo-dpkg authored Oct 3, 2024
2 parents ff8e3da + 88536c8 commit 38cf72b
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/components/Manager.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,26 @@ const Manager = () => {
};

const savePassword = async () => {
const passwordValidation = (password) => {
const minLength = 8;
const hasUpperCase = /[A-Z]/.test(password);
const hasLowerCase = /[a-z]/.test(password);
const hasNumbers = /\d/.test(password);
const hasSpecialChars = /[!@#$%^&*(),.?":{}|<>]/.test(password);

return (
password.length >= minLength &&
hasUpperCase &&
hasLowerCase &&
hasNumbers &&
hasSpecialChars
);
};

if (
form.site.length > 3 &&
form.username.length > 3 &&
form.password.length > 3
form.username.length >= 3 &&
passwordValidation(form.password)
) {
if (form.id) {
// Update existing password
Expand All @@ -74,7 +90,7 @@ const Manager = () => {
body: JSON.stringify(newPassword),
});
}

setForm({ id: "", site: "", username: "", password: "" });
toast("Password saved!", {
position: "top-right",
Expand All @@ -87,9 +103,10 @@ const Manager = () => {
theme: "dark",
});
} else {
toast("Error: Password not saved!");
toast("Error: Password not saved! Ensure the password meets all criteria.");
}
};


const deletePassword = async (id) => {
const confirmDelete = confirm(
Expand Down

0 comments on commit 38cf72b

Please sign in to comment.