lock-score
v1.1.1
Published
A React component to check password strength and display criteria validation.
Maintainers
Readme
🔒 lock-score: React Password Strength Meter
A lightweight, zero-dependency React component to check and visually display password strength and validation criteria. Built with TypeScript utility classes (for easy integration).
✨ Features
- Visual Strength Bar: Displays password strength using a 4-level color-coded bar (ranging from Very Weak to Strong).
- Detailed Criteria: Shows a clear list of criteria (e.g., minimum length, uppercase, number, special character) and whether they are met.
- Customizable: Easily hide the criteria list using the
showCriteriaprop. - Type-Safe: Developed with TypeScript for a reliable and robust developer experience.
- Zero Dependencies: No extra libraries required for core functionality (uses
lucide-reactfor icons).
📦 Installation
You can install this package in your React project using npm or yarn.
npm install lock-score
# or
yarn add lock-score🔨 Usage
⚛️ Usage (React Component)
Place the PasswordStrengthMeter component below your password input field. It will automatically calculate and display the strength based on the string provided in the password prop.
import React, { useState } from 'react';
import { PasswordStrengthMeter } from 'lock-score';
const SignupForm = () => {
const [password, setPassword] = useState('');
return (
<div style={{ maxWidth: '400px', margin: 'auto', padding: '20px' }}>
<label htmlFor="password-input" className="block text-sm font-medium text-gray-700">
New Password
</label>
<input
id="password-input"
type="password"
value={password}
onChange={(e) => setPassword(e.target.value)}
className="mt-1 block w-full border border-gray-300 rounded-md shadow-sm p-2"
placeholder="Enter your password"
/>
{/* 1. Use the Password Strength Meter */}
<PasswordStrengthMeter
password={password}
className="p-1 border-t border-gray-200"
/>
{/* 2. You can hide the criteria list if needed */}
{/* <PasswordStrengthMeter
password={password}
showCriteria={false}
/> */}
</div>
);
};
export default SignupForm;⚙️ Component Props
| Prop | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| password | string | Required | The raw password string to check for strength. |
| showCriteria | boolean | true | If false, the detailed validation criteria list will be hidden. |
| className | string | "" | Custom CSS classes to apply to the outer div element. |
💡 Strength Logic (Utility Functions)
The core strength calculation logic is exported as separate utility functions, which you can use independently of the React component:
| Function | Description |
| :--- | :--- |
| calculateStrength(password) | Calculates the strength score (0 to 4) for the given password. |
| checkCriteria(password) | Returns a detailed array of criteria and their fulfillment status (met: boolean). |
| getStrengthText(strength) | Returns the strength rating text based on the score (e.g., "Strong"). |
| getStrengthColor(strength) | Returns the corresponding Tailwind color class based on the score (e.g., "bg-green-500"). |
TypeScript
import { calculateStrength, getStrengthText } from 'lock-score';
const myPassword = "StrongPassword@123";
const score = calculateStrength(myPassword); // Output: 4
const text = getStrengthText(score); // Output: "Strong"
console.log(`Password is: ${text} (Score: ${score})`);👤 Author & Contributor
This package is maintained and developed by Hamza Tayyab. I am passionate about creating clean, efficient, and secure frontend tools. Feel free to connect or check out my other projects!
| Platform | Link | | :--- | :--- | | 🌐 Portfolio | https://linktr.ee/hm.za | | 📧 Email | [email protected] | | 💻 GitHub | Follow me on GitHub https://github.com/hmzatayab | | 🎁 Other Packages | Check out my other open-source projects https://www.npmjs.com/~hamzatayab |
📄 License
MIT License
Copyright (c) [2025] [Hamza Tayyab]
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
