Created
May 18, 2013 14:32
-
-
Save michaelficarra/5604604 to your computer and use it in GitHub Desktop.
example password strength meter using lowe/zxcvbn
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
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title></title> | |
| <style> | |
| .meter { | |
| width: 300px; | |
| height: 50px; | |
| border: 1px solid #666; | |
| position: relative; | |
| } | |
| .meter > .bar { | |
| position: absolute; | |
| top: 75%; | |
| bottom: 0; | |
| left: 0; | |
| right: 0; | |
| background-image: linear-gradient(to left, #A3FF5C 0%, #EF1F3B 5%); | |
| } | |
| #password { | |
| position: absolute; | |
| top: 0; | |
| bottom: 25%; | |
| left: 0; | |
| right: 0; | |
| font-size: 28px; | |
| border: 0; | |
| } | |
| </style> | |
| <script src=zxcvbn.js></script> | |
| </head> | |
| <body> | |
| <div class=meter> | |
| <input type=password id=password /> | |
| <div class=bar></div> | |
| </div> | |
| <script> | |
| var input = document.getElementById('password'); | |
| var bar = document.getElementsByClassName('bar')[0]; | |
| input.addEventListener('keyup', function(){ | |
| var analysis = zxcvbn(input.value); | |
| var entropy = analysis.entropy * 4 + 5; | |
| bar.style.backgroundImage = 'linear-gradient(to left, #A3FF5C 0%, #EF1F3B ' + (entropy | 0) + '%)'; | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment