From 81081e291b39bb069d05c2f838fbeffce38ca744 Mon Sep 17 00:00:00 2001 From: Tane Piper Date: Mon, 21 Jun 2010 23:59:30 +0100 Subject: [PATCH] Added email check rule to core widget, added README and LICENCE --- LICENCE | 21 ++++++++++ README | 92 ++++++++++++++++++++++++++++++++++++++++++++ src/ui.pwstrength.js | 5 +++ 3 files changed, 118 insertions(+) create mode 100644 LICENCE create mode 100644 README diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..bf8203f --- /dev/null +++ b/LICENCE @@ -0,0 +1,21 @@ +The MIT License + +Copyright (c) 2010 Tane Piper + +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. diff --git a/README b/README new file mode 100644 index 0000000..058bd50 --- /dev/null +++ b/README @@ -0,0 +1,92 @@ +================================ +jQueryUI Password Strength Meter +================================ + +The jQuery UI Password Strength Meter is a widget for jQueryUI that provides +rulesets for visualy displaying the quality of a users typed in password. + +The widget requires jQueryUI 1.8 core and progress meter. + +Options +======= + +minChar: + Default: 8 (Integer) + Sets the minimum required of characters for a password to not be considered + too weak + +progressClass: + Default: ['zero', 'twenty-five', 'fifty', 'seventy-five', 'one-hundred'] (Array) + The names of the classes that are added to the visual display bar, used to + provide CSS overide for display + +verdicts: + Default: ["Weak", "Normal", "Medium", "Strong", "Very Strong"] (Array) + The display names for the verdicts related to the progressClass + +scores: + Default: [17, 26, 40, 50] (Array) + The scores used to determine what progressClass and verdicts to display + +showVerdicts: + Default: true (Boolean) + Determines if the verdicts are display on the progress bar or not + +usernameField: + Default: "#username" (String) + The username field to match a password to, to ensure the user does not use + the same value for their password + +raisePower: + Default: 1.4 (Double) + The value used to modify the final score, allows you to tailor your results + +onLoad: + Default: undefined (Function) + A callback function, fired on load of the widget + +onKeyUp: + Default: undefined (Function) + A callback function, fired on key up when the user is typing + +errorMessages: + Default: { + password_to_short : "The Password is too short", + same_as_username : "Your password cannot be the same as your username" + } (Object) + An object containing error messages. These can be overwritten for language + purposes, and can also be added to for your custom rules. + + +Adding Custom Rules +=================== + +The widget comes with the functionality to easily define your own custom rules. + +An example is as follows + +The format is as follows: + $.ui.pwstrength.addRule("ruleName", function(ui, word, score) {}, rule_score, rule_enabled); + +Example: + $.ui.pwstrength.addRule("testRule", function(ui, word, score) { + return word.match(/[a-z].[0-9]/) && score; + }, 10, true); + + +Callback Functions +================== + +The widget provides two callback functions, onLoad and onKeyUp. You can use them like this: + +$(document).ready(function(){ + var options = { + onLoad: function() { + $('#messages').text('Start typing password'); + }, + onKeyUp: function() { + $('#messages').html($.ui.pwstrength.outputErrorList()); + } + } + $(':password').pwstrength(options); +}); diff --git a/src/ui.pwstrength.js b/src/ui.pwstrength.js index 40baa9c..e65521b 100644 --- a/src/ui.pwstrength.js +++ b/src/ui.pwstrength.js @@ -148,6 +148,7 @@ $.ui.pwstrength.rules[rule] = active; }, ruleScores : { + wordNotEmail: -100, wordLength : -100, wordSimilarToUsername : -100, wordLowercase : 1, @@ -161,6 +162,7 @@ wordLetterNumberCharCombo : 2 }, rules : { + wordNotEmail: true, wordLength : true, wordSimilarToUsername :true, wordLowercase : true, @@ -174,6 +176,9 @@ wordLetterNumberCharCombo : true }, validationRules : { + wordNotEmail : function ( ui, word, score ) { + return word.match(/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i) && score; + }, wordLength : function( ui, word, score ) { var options = ui.options; var wordlen = word.length;