Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

password validater in JS #748

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions scripts/premdaripa.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
function validatePassword(password) {
// Define the regular expressions for various password criteria
const minLength = 8; // Minimum password length
const hasUppercase = /[A-Z]/;
const hasLowercase = /[a-z]/;
const hasDigit = /[0-9]/;
const hasSpecialChar = /[!@#$%^&*()_+{}\[\]:;<>,.?~\\/-]/; // You can customize this list of special characters

// Check the minimum length
if (password.length < minLength) {
return false;
}

// Check for uppercase letters
if (!hasUppercase.test(password)) {
return false;
}

// Check for lowercase letters
if (!hasLowercase.test(password)) {
return false;
}

// Check for at least one digit
if (!hasDigit.test(password)) {
return false;
}

// Check for at least one special character
if (!hasSpecialChar.test(password)) {
return false;
}

// If all criteria are met, the password is valid
return true;
}

// Example usage:
const password = "MyP@ssw0rd";
const isValid = validatePassword(password);

if (isValid) {
console.log("Password is valid.");
} else {
console.log("Password is invalid.");
}