Password Matching using JavaScript Last Updated : 30 Sep, 2024 Comments Improve Suggest changes Like Article Like Report In an online application form or social media signup page, it's common to have two input fields: one for the password and another for confirming the password. The goal is to check whether the entered passwords match.To achieve this, the first password is stored in a variable password1, and the confirmation password is stored in password2. We then compare the values of these two variables. If both values are equal, it indicates that the passwords match; otherwise, it means they do not match.This is a simple and effective way to ensure the user has entered the same password in both fields.Example: Below is the implementation of the above approach: HTML <!DOCTYPE html> <html> <head> <style> .gfg { font-size: 40px; color: green; font-weight: bold; text-align: center; } .geeks { font-size: 17px; text-align: center; margin-bottom: 20px; } </style> </head> <body> <div class="gfg">GeeksforGeeks</div> <div class="geeks">A computer science portal for geeks</div> <form onSubmit="return checkPassword(this)"> <table border=1 align="center"> <tr> <!-- Enter Username --> <td>Username:</td> <td><input type=text name=name size=25</td> </tr> <tr> <!-- Enter Password. --> <td>Password:</td> <td><input type=password name=password1 size=25</td> </tr> <tr> <!-- To Confirm Password. --> <td>Confirm Password:</td> <td><input type=password name=password2 size=25></td> </tr> <tr> <td colspan=2 align=right> <input type=submit value="Submit"> </td> </tr> </table> </form> <script> // Function to check Whether both passwords // is same or not. function checkPassword(form) { password1 = form.password1.value; password2 = form.password2.value; // If password not entered if (password1 == '') alert("Please enter Password"); // If confirm password not entered else if (password2 == '') alert("Please enter confirm password"); // If Not same return False. else if (password1 != password2) { alert("\nPassword did not match: Please try again...") return false; } // If same return True. else { alert("Password Match: Welcome to GeeksforGeeks!") return true; } } </script> </body> </html> Output: Comment More infoAdvertise with us Next Article Password Matching using JavaScript N Naman_Garg Follow Improve Article Tags : JavaScript Web Technologies Similar Reads Show And Hide Password Using JavaScript When creating login or registration forms, a common feature is the ability to show and hide passwords. This improves user experience by allowing users to verify their input before submitting the form.What We're Going to CreateWe will create a "Password Hide and Show" feature that will allow users to 4 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 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 Build a Password Manager using React Password manager using React js provides a secure and user-frieÂndly environment for users to store and manage their credeÂntials. It offers convenient feÂatures like adding, editing, and deÂleting password entries. The user can show/hide their password by clicking on a particular button. Preview o 6 min read Create a Password Manager using React-Native This article will demonstrate how to create a Password Manager Application using React-Native. To assist users in securely storing and managing their passwords, we will develop a Password Manager mobile application using React Native for this project. The application will provide functionalities su 15+ min read How to Generate a Random Password using JavaScript? Creating a random password generator is an excellent beginner-friendly project that can be useful in real-world applications. Passwords are vital for securing accounts, and strong, randomized passwords enhance security significantly. How to Generate a Random Password using JavaScriptWhat We're Going 5 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 Bootstrap & JavaScript 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. PrerequisitesHTMLBootstrapJavaScriptApproac 3 min read How to make a Password Input using jQuery Mobile ? jQuery Mobile is a web based technology used to make responsive content that can be accessed on all smartphones, tablets and desktops. In this article, we will be creating a Password Input using jQuery Mobile. Approach: Add jQuery Mobile scripts needed for your project. <link rel=âstylesheetâ hre 1 min read Password Encryption in Node.js using bcryptjs Module When developing applications, one of the critical aspects of user authentication is ensuring that passwords are stored securely. Plain text storage of passwords is a significant security risk. Instead, passwords should be encrypted using strong hashing algorithms. In Node.js, one of the popular modu 3 min read Like