Created
October 23, 2025 03:08
-
-
Save panphora/8f4d620ae92e8b28dcb4f20152185749 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { useState } = React; | |
| const PasswordStrength = () => { | |
| const [password, setPassword] = useState(''); | |
| const requirements = [ | |
| { label: '8+ characters', check: (pwd) => pwd.length >= 8 }, | |
| { label: '12+ characters', check: (pwd) => pwd.length >= 12 }, | |
| { label: 'Lowercase letter', check: (pwd) => /[a-z]/.test(pwd) }, | |
| { label: 'Uppercase letter', check: (pwd) => /[A-Z]/.test(pwd) }, | |
| { label: 'Number', check: (pwd) => /\d/.test(pwd) }, | |
| { label: 'Special character', check: (pwd) => /[^a-zA-Z0-9]/.test(pwd) } | |
| ]; | |
| return ( | |
| <div className="w-80 p-6 bg-white rounded-xl shadow-lg space-y-4"> | |
| <input | |
| type="password" | |
| value={password} | |
| onChange={(e) => setPassword(e.target.value)} | |
| placeholder="Enter password" | |
| className="w-full px-4 py-2 border rounded-lg focus:outline-none focus:ring-2" | |
| /> | |
| <div className="space-y-2"> | |
| {requirements.map((req, idx) => { | |
| const isMet = req.check(password); | |
| return ( | |
| <div key={idx} className="flex items-center gap-2"> | |
| <div className={`w-5 h-5 rounded-full flex items-center justify-center text-xs font-bold | |
| ${isMet ? 'bg-green-500 text-white' : 'bg-gray-200 text-gray-400'}`}> | |
| {isMet ? '✓' : ''} | |
| </div> | |
| <span className={`text-sm ${isMet ? 'text-green-600 font-medium' : 'text-gray-500'}`}> | |
| {req.label} | |
| </span> | |
| </div> | |
| ); | |
| })} | |
| </div> | |
| </div> | |
| ); | |
| }; | |
| const root = ReactDOM.createRoot(document.getElementById('react-root')); | |
| root.render(<PasswordStrength />); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Context: author's article React vs. Backbone in 2025
FWiW, I've semi-golfed some kind of a uglier vanilla HTML+CSS remake of the functionality with single line of JS, with all flaws preserved, but still keeping quite "followable" code (I hope), under 40 LOC total (*). I see the author is quite into hacking with HTML, so I guess they surely could have done similar demo on their own, but it wouldn't fit into the scope of the article.
* I guess nowadays it could be turned into CSS-only abomination, but it would still require duplicating logic between HTML and CSS, what I wanted to avoid; that's why the tiny JS in there.