Create a Password Validator using Bootstrap & JavaScript Last Updated : 27 Feb, 2024 Comments Improve Suggest changes Like Article Like Report A password validator assesses password strength by verifying if it meets predetermined criteria like length, inclusion of uppercase and lowercase letters, digits, and symbols. It ensures robust security measures for user authentication and data protection. PrerequisitesHTMLBootstrapJavaScriptApproachThe provided code is a password strength checker implemented in JavaScript. It assesses password strength by evaluating length, character diversity, and complexity. It dynamically updates a list of conditions such as minimum length, presence of uppercase and lowercase letters, and symbols, displaying whether each condition is met. Additionally, it toggles password visibility and provides feedback on password strength, indicating whether it's strong or weak, along with visual cues for each condition. Example: This example shows the implementation of the above-explained approach. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Password Strength Checker</title> <!-- Bootstrap CSS --> <link href= "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"> <!-- Font Awesome --> <link href= "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet"> </head> <body> <div class="container mt-5"> <div class="row justify-content-center"> <div class="col-md-6"> <div class="card"> <div class="card-body"> <h2 class="mb-4"> Checking Password Strength in JavaScript </h2> <div class="form-group"> <label for="password">Enter Password:</label> <div class="input-group"> <input type="password" class="form-control" id="password" oninput="validatePassword(this.value)"> <div class="input-group-append"> <button class="btn btn-outline-secondary" type="button" id="togglePassword"> <i class="fas fa-eye"></i> </button> </div> </div> </div> <div class="form-group"> <ul> <li id="minLength"><i class="fas fa-times text-danger"></i> Minimum 8 characters</li> <li id="uppercase"><i class="fas fa-times text-danger"></i> At least one uppercase letter</li> <li id="lowercase"><i class="fas fa-times text-danger"></i> At least one lowercase letter</li> <li id="symbol"><i class="fas fa-times text-danger"></i> At least one symbol (@$!%*?&) </li> </ul> </div> <span id="errorMessage" class="font-weight-bold text-danger"></span> </div> </div> </div> </div> </div> <!-- Bootstrap JS and jQuery --> <script src= "https://code.jquery.com/jquery-3.5.1.slim.min.js"></script> <script src= "https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.bundle.min.js"> </script> <!-- Font Awesome --> <script src= "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/js/all.min.js"> </script> <script> // Function to toggle password visibility document.getElementById('togglePassword').addEventListener('click', function () { const passwordInput = document.getElementById('password'); const icon = this.querySelector('i'); if (passwordInput.type === 'password') { passwordInput.type = 'text'; icon.classList.remove('fa-eye'); icon.classList.add('fa-eye-slash'); } else { passwordInput.type = 'password'; icon.classList.remove('fa-eye-slash'); icon.classList.add('fa-eye'); } }); function validatePassword(password) { const strongPasswordRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/; const errorMessage = document.getElementById('errorMessage'); // Check each condition and update the corresponding label document.getElementById('minLength').innerHTML = password.length >= 8 ? '<i class="fas fa-check text-success"></i> Minimum 8 characters' : '<i class="fas fa-times text-danger"></i> Minimum 8 characters'; document.getElementById('uppercase').innerHTML = /[A-Z]/.test(password) ? '<i class="fas fa-check text-success"></i> At least one uppercase letter' : '<i class="fas fa-times text-danger"></i> At least one uppercase letter'; document.getElementById('lowercase').innerHTML = /[a-z]/.test(password) ? '<i class="fas fa-check text-success"></i> At least one lowercase letter' : '<i class="fas fa-times text-danger"></i> At least one lowercase letter'; document.getElementById('symbol').innerHTML = /[@$!%*?&]/.test(password) ? '<i class="fas fa-check text-success"></i> At least one symbol (@$!%*?&)' : '<i class="fas fa-times text-danger"></i> At least one symbol (@$!%*?&)'; // Check overall validity and update the error message if (strongPasswordRegex.test(password)) { errorMessage.textContent = 'Strong Password'; errorMessage.classList.remove('text-danger'); errorMessage.classList.add('text-success'); } else { errorMessage.textContent = 'Weak Password'; errorMessage.classList.remove('text-success'); errorMessage.classList.add('text-danger'); } } </script> </body> </html> Output: Comment More infoAdvertise with us Next Article Create a Password Validator using Bootstrap & JavaScript G geekcoder2298 Follow Improve Article Tags : Project JavaScript Web Technologies Dev Scripter Dev Scripter 2024 +1 More Similar Reads Validate a password using HTML and JavaScript Validating a password using HTML and JavaScript involves ensuring that user-entered passwords meet certain criteria, such as length, complexity, or character types (e.g., uppercase, lowercase, numbers, and symbols). This process enhances security by enforcing strong password requirements before form 2 min read Password Validation Form Using JavaScript The password Validation form is used to check the password requirements such as the password must have at least one Uppercase, or lowercase, number, and the length of the password. We can also check this after submitting the form but it's not recommended. We can easily check before submitting the fo 4 min read How to validate confirm password using JavaScript ? In almost every modern website we have seen a login and signup feature, which is surely an important service for both the client and the service provider. When a user signs up for a certain website they have to put in a username a password, to enter the password websites ask them to enter a password 3 min read Create a Password Validator using Tailwind CSS Passwords must be strong so that hackers can not hack them easily. The following example shows how to check the password strength of the user input password in Tailwind CSS and jQuery. We will use the validator module to achieve this functionality. We will call the isStrongPassword function and pass 3 min read Create a Password Validator using ReactJS Password must be strong so that hackers can not hack them easily. The following example shows how to check the password strength of the user input password in ReactJS. We will use the validator module to achieve this functionality. We will call the isStrongPassword function and pass the conditions a 2 min read OTP Generator and Validator Card using JavaScript & Tailwind CSS OTP (One-Time Password) generator and validator built using Tailwind CSS and JavaScript allows users to generate a random OTP and validate it against the entered OTP. The application has a user-friendly interface for generating and validating OTPs using JavaScript for interactivity and Tailwind CSS 3 min read How to Create a Bootstrap Form Validation ? A Bootstrap Form Validation ensures that user input complies with established standards before submission, improves the user experience, and minimizes server-side processing for incorrect inputs. We can add client-side validation to their forms by using two different methods including Bootstrap buil 3 min read How to Toggle Password Visibility using HTML and JavaScript ? In this article, we will learn about how to toggle password visibility using HTML and JavaScript. Passwords are those input types that take hidden inputs. It can be shown and hidden from the user by toggling its type between text and password. Approach The following approach will be implemented to t 2 min read How to create a web page using Bootstrap ? Bootstrap is an open-source CSS framework for creating a responsive and customizable frontend for websites and web applications. Using Bootstrap's grid system one can easily create a web page very fast. Any webpage these days needs to have a navbar for user navigation, some content & a form for 6 min read How to create a vertical or basic form using Bootstrap ? Forms are used on almost every website that you visit. It is generally used to collect data from the users. It consists of various interactive controls that enable users to input the data. These controls are wrapped in the <form> tag and also can be designed or styled according to the need by 4 min read Like