jQuery Password Strength Checker
Create a jQuery password strength checker in 2025. Boost security with this example.

Password strength is very important for online security. A strong password protects user accounts from being hacked. It depends on the length, unpredictability, and mix of letters, numbers, and special characters.
Many websites, like Gmail, show a password strength indicator when you create an account. In this guide, we will show you how to build your own password strength checker using jQuery. We will provide step-by-step instructions and a downloadable demo to make it easy for beginners.
Why Password Strength Matters
- Protects accounts: Strong passwords make it harder for hackers to guess.
- Prevents brute-force attacks: Longer and complex passwords are safer.
- Protects personal information: Sensitive user data stays safe.
By creating a password strength checker, you can help users create safer passwords.
Password Strength Criteria
Our checker will look at these things:
- Length: More characters = stronger password.
- Uppercase letters: Adds complexity (A-Z).
- Lowercase letters: Adds unpredictability (a-z).
- Numbers: Increases difficulty for attackers (0-9).
- Special characters: Symbols like !, @, #, $, % make the password stronger.
Based on these checks, the password will be rated as Very Weak
, Weak
, Strong
, or Very Strong
.
Step 1: Add a Password Field
Check your form for the password input. Give it a class or ID. Here we use class="password"
, but you can choose any name.
<input type="password" autocomplete="off" name="password" class="password" />
autocomplete="off"
to prevent browsers from suggesting old passwords in your field.
Step 2: Include jQuery Library
Link the jQuery library in your project. You can use a CDN link or a local copy. We use a CDN in this example.
<script type="text/javascript" src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
Step 3: Include Password Strength Checker JavaScript File
To make our password strength checker work, we use a small JavaScript file called password_strength_checker.js
. This file contains all the logic to calculate how strong a password is and display the result in real-time.
Here’s what this file does:
- Check password length: Ensures the password is long enough for security.
- Check character types: Counts numbers, lowercase letters, uppercase letters, and special characters.
- Calculate strength: Gives a score based on the combination of character types and length.
- Assign levels: Converts the score to easy-to-understand levels like Too weak, Weak, Normal, Strong, and Very strong.
- Update UI: Shows the strength text and optionally a color bar as the user types.
- Optional callback: Developers can run extra actions whenever password strength is updated.
(function($){
$.fn.password_strength = function(options) {
var settings = $.extend({
container: null,
bar: null,
minLength: 6,
texts: {
1: 'Too weak',
2: 'Weak password',
3: 'Normal strength',
4: 'Strong password',
5: 'Very strong password'
},
onCheck: null
}, options);
return this.each(function() {
var $input = $(this);
var $container = settings.container ? $(settings.container) : $('<span class="password_strength"></span>').insertAfter($input);
var $bar = settings.bar ? $(settings.bar) : null;
function getLevel(val) {
if (val.length < settings.minLength) return 1;
var strength = 0;
if (/[0-9]/.test(val)) strength += 2;
if (/[a-z]/.test(val)) strength += 2;
if (/[A-Z]/.test(val)) strength += 2;
if (/[^a-zA-Z0-9]/.test(val)) strength += 3;
// Add bonus for very long passwords
if (val.length >= 12) strength += 2; // increase max points
// Map score to levels 1-5
if (strength <= 3) return 2;
else if (strength <= 6) return 3;
else if (strength <= 9) return 4;
else return 5; // now complex passwords can reach 5
}
$input.on('keyup', function() {
var val = $input.val();
var level = getLevel(val);
$container.text(settings.texts[level]).attr('class', 'password_strength password_strength_' + level);
if ($bar) $bar.attr('class', 'password_bar password_bar_' + level);
if (settings.onCheck) settings.onCheck.call(this, level);
});
if ($input.val() !== '') $input.trigger('keyup');
});
};
})(jQuery);
This file works with jQuery, so make sure your page includes jQuery before using it. The file is simple, lightweight, and easy to customize to fit any website or project.
<script type="text/javascript" src="js/password_strength_checker.js"></script>
Step 4: Call the Password Strength Function
Call the function on your password field to activate the strength checker.
$(function() {
$('.password').password_strength();
});
Example Use Case: When a user types a password in a signup form, they see a live color indicator showing if the password is weak or strong.
Example: Full HTML Structure
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="container">
<div id="top"><a href="https://www.php-dev-zone.com/">PHP Dev Zone </a> : <i>Password Strength Indicator </i></div>
<div id="wrapper">
<div id="form">
<label>Password : </label>
<input type="password" autocomplete="off" name="password" class="password" />
</div>
</div>
<div id="bottom"><a href="https://www.php-dev-zone.com/post/enhance-account-security-with-a-password-strength-checker-using-jquery"> Go back to tutorial</a></div>
</div>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script type="text/javascript" src="js/password_strength_checker.js"></script>
<script type="text/javascript">
$(function() {
$('.password').password_strength();
});
</script>
</body>
</html>
Real Use Cases for Password Strength Checker
- Signup forms: Guide users to create strong passwords immediately.
- Login systems: Warn users if their password is weak and needs updating.
- Admin panels: Ensure employees use strong passwords for company security.
- Membership websites: Reduce the chance of hacked accounts by enforcing strong passwords.
Tips to Make Strong Passwords
- Use at least 12 characters.
- Mix uppercase and lowercase letters.
- Add numbers and special symbols.
- Do not use easily guessable words like "password" or "123456".
- Use different passwords for different websites.
Download Demo Code
You can download the ready-to-use demo and customize it for your own site:
FAQs
Q1: Can beginners use this script?
Yes! This guide is beginner-friendly and shows step-by-step instructions.
Q2: Can I change colors for password strength?
Yes, you can edit the CSS file to show different colors for weak, medium, or strong passwords.
Q3: Does it work on mobile devices?
Yes, the script works on all devices that support jQuery.
Conclusion
Creating a password strength checker is simple but very important. By using jQuery and following the steps above, you can give users live feedback on their password strength and improve overall account security.
This small feature can prevent weak passwords and protect sensitive data. Make it part of every signup or account system you build. Encourage users to create strong, unpredictable passwords.
We hope this guide was easy to follow. Try it yourself, and feel free to customize it to match your website’s design.
0 Comments