Skip to content

Commit

Permalink
Added email check rule to core widget, added README and LICENCE
Browse files Browse the repository at this point in the history
  • Loading branch information
Tane Piper committed Jun 21, 2010
1 parent ce581f0 commit 81081e2
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENCE
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2010 Tane Piper <github@digitalspaghetti.me.uk>

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.
92 changes: 92 additions & 0 deletions 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);
});
5 changes: 5 additions & 0 deletions src/ui.pwstrength.js
Expand Up @@ -148,6 +148,7 @@
$.ui.pwstrength.rules[rule] = active;
},
ruleScores : {
wordNotEmail: -100,
wordLength : -100,
wordSimilarToUsername : -100,
wordLowercase : 1,
Expand All @@ -161,6 +162,7 @@
wordLetterNumberCharCombo : 2
},
rules : {
wordNotEmail: true,
wordLength : true,
wordSimilarToUsername :true,
wordLowercase : true,
Expand All @@ -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;
Expand Down

0 comments on commit 81081e2

Please sign in to comment.