| CODENOTIFIER | HelpYou are not signed inSign in |
Project: jQuery
Revision: 5834
Author: joern.zaefferer
Date: 19 Aug 2008 13:27:44
Diff at Trac: http://dev.jquery.com/changeset/5834
Changes:validate: first prototype for password validation including password strength meter
Files:| ... | ...@@ -0,0 +1,51 @@ | |
| 1 | (function() { | |
| 2 | ||
| 3 | var input; | |
| 4 | var messages = $.validator.passwordRating.messages; | |
| 5 | ||
| 6 | function check(messageKey) { | |
| 7 | input.valid(); | |
| 8 | if (!messageKey) { | |
| 9 | equals( input.next(":visible").text(), $.validator.messages.required ); | |
| 10 | } else { | |
| 11 | equals( input.next(":visible").text(), messages[messageKey] ); | |
| 12 | } | |
| 13 | } | |
| 14 | ||
| 15 | test("basic password strength meter", function() { | |
| 16 | ||
| 17 | $("#form").validate(); | |
| 18 | ||
| 19 | input = $("#password"); | |
| 20 | check(); | |
| 21 | ||
| 22 | input.val("a"); | |
| 23 | check("too-short"); | |
| 24 | ||
| 25 | input.val(""); | |
| 26 | check(); | |
| 27 | ||
| 28 | input.val("abc123@po"); | |
| 29 | check("strong"); | |
| 30 | }); | |
| 31 | ||
| 32 | test("check similar username", function() { | |
| 33 | ||
| 34 | input = $("#password").removeClass(); | |
| 35 | ||
| 36 | $("#form").validate({ | |
| 37 | rules: { | |
| 38 | password: { | |
| 39 | required: true, | |
| 40 | password: "#username" | |
| 41 | } | |
| 42 | } | |
| 43 | }); | |
| 44 | ||
| 45 | check(); | |
| 46 | ||
| 47 | input.val("peterpeter"); | |
| 48 | check("similar-to-username"); | |
| 49 | }); | |
| 50 | ||
| 51 | })(); | |
| 0 | 52 | \ No newline at end of file |
| ... | ...@@ -0,0 +1,33 @@ | |
| 1 | <html id="html"> | |
| 2 | <head> | |
| 3 | <title>jQuery Validation Plugin Password Extension Test Suite</title> | |
| 4 | <link rel="Stylesheet" media="screen" href="qunit/testsuite.css" /> | |
| 5 | <script type="text/javascript" src="../../validate/lib/jquery.js"></script> | |
| 6 | <script type="text/javascript" src="../lib/ui.core.js"></script> | |
| 7 | <script type="text/javascript" src="../lib/ui.progressbar.js"></script> | |
| 8 | <script type="text/javascript" src="qunit/testrunner.js"></script> | |
| 9 | <script type="text/javascript" src="../../validate/jquery.validate.js"></script> | |
| 10 | <script type="text/javascript" src="../jquery.validate.password.js"></script> | |
| 11 | <script type="text/javascript" src="rating.js"></script> | |
| 12 | <script type="text/javascript" src="strength-meter.js"></script> | |
| 13 | ||
| 14 | <style type="text/css"> | |
| 15 | .xerror, .error { display: none } | |
| 16 | </style> | |
| 17 | </head> | |
| 18 | <body id="body"> | |
| 19 | <h1><a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/">jQuery Validation Plugin Password Extension</a> Test Suite</h1> | |
| 20 | <h2 id="banner"></h2> | |
| 21 | <h2 id="userAgent"></h2> | |
| 22 | ||
| 23 | <div id="main" style="display:none;"> | |
| 24 | <form id="form"> | |
| 25 | <input id="username" name="username" value="Peter" /> | |
| 26 | <input class="required password" name="password" id="password" /> | |
| 27 | </form> | |
| 28 | </div> | |
| 29 | ||
| 30 | <ol id="tests"></ol> | |
| 31 | ||
| 32 | </body> | |
| 33 | </html> |
| ... | ...@@ -0,0 +1,39 @@ | |
| 1 | test("ratings", function() { | |
| 2 | ||
| 3 | function rates(password, expectedMessage, expectedRating, username) { | |
| 4 | var rating = $.validator.passwordRating(password, username); | |
| 5 | equals(rating.rate, expectedRating, "rating for " + password); | |
| 6 | equals(rating.messageKey, expectedMessage); | |
| 7 | } | |
| 8 | ||
| 9 | rates(null, "too-short", 0); | |
| 10 | rates("", "too-short", 0); | |
| 11 | rates("a", "too-short", 0); | |
| 12 | rates("abcdefg", "too-short", 0); | |
| 13 | ||
| 14 | // long enough, but too simple: very weak | |
| 15 | rates("aaaaaaaa", "very-weak", 1); | |
| 16 | rates("@@@@@@@@", "very-weak", 1); | |
| 17 | ||
| 18 | // long enough and mixed characters: weak | |
| 19 | rates("Computer", "weak", 2); | |
| 20 | rates("computer", "weak", 2); | |
| 21 | rates("abcdefgh", "weak", 2); | |
| 22 | ||
| 23 | // letters and a number or upper and lowercase letters: good | |
| 24 | rates("computer1", "good", 3); | |
| 25 | rates("cOmputer", "good", 3); | |
| 26 | ||
| 27 | // letters and numbers or upper/lower and number, or letter and special: strong | |
| 28 | rates("computer12", "strong", 4); | |
| 29 | rates("c@mputer", "strong", 4); | |
| 30 | rates("cOmputer2", "strong", 4); | |
| 31 | ||
| 32 | // long pass phrase | |
| 33 | rates("my uncle ben has my password safe in his safe", "strong", 4); | |
| 34 | ||
| 35 | // differ from username | |
| 36 | rates("computer", "similar-to-username", 0, "computer"); | |
| 37 | rates("cOmputer1", "similar-to-username", 0, "computer"); | |
| 38 | ||
| 39 | }); |