From 6d759854c689bb70375247aad4c8906c909fab03 Mon Sep 17 00:00:00 2001 From: steinm Date: Tue, 28 Aug 2012 07:26:11 +0000 Subject: [PATCH] - added jquery plugin which runs ajax command for calculating password strength --- js/jquery.passwordstrength.js | 69 +++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 js/jquery.passwordstrength.js diff --git a/js/jquery.passwordstrength.js b/js/jquery.passwordstrength.js new file mode 100644 index 000000000..9ce0e9ad4 --- /dev/null +++ b/js/jquery.passwordstrength.js @@ -0,0 +1,69 @@ +/** + * jquery.passwordstrength.js + * Copyright (c) 2012 Uwe Steinmann + + + * 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. + * + * @author Uwe Steinmann + * @date 2012-06-08 + * @projectDescription Password Strength Meter is a jQuery plug-in provide you smart algorithm to detect a password strength. + * @version 0.0.1 + * + * @requires jquery.js + * @param url: ajax url, + * @param pwd: password + * +*/ + +(function($){ + + $.fn.passStrength = function(options) { + + var defaults = { + minscore: 50 + }; + var opts = $.extend(defaults, options); + + return this.each(function() { + var obj = $(this); + + $(obj).unbind().keyup(function() { + if($(this).val()) + $("#outerstrength").show(); + else + $("#outerstrength").hide(); + $.getJSON(opts.url, + {command: 'checkpwstrength', pwd: $(this).val()}, + function(data) { + if(data.error) { + } else { + $("#strength").html(Math.round(data.strength)); + $("#innerstrength").width(data.strength); + if(data.strength > opts.minscore) { + $("#innerstrength").css('background-color', 'green'); + } else { + $("#innerstrength").css('background-color', 'red'); + } + } + }); + }); + }); + }; +})(jQuery);