Advertisement
wallacesilva09

pStrength - Medidor de força de senha com jQuery

Jul 24th, 2012
1,532
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 4.60 KB | None | 0 0
  1. /**
  2.  * Fonte/Source: http://code.google.com/p/macademia/source/browse/trunk/Macademia/web-app/js/jquery/jquery.pstrength.min.js?spec=svn300&r=251
  3.  * Traduzido por/Translated by: Wallace Silva <contato [at] wallacesilva [dot] com>
  4.  * Edited by: Wallace Silva
  5.  * Last Modified: 24/07/2012
  6.  */
  7. (function(a) {
  8.     a.extend(a.fn, {pstrength:function(b) {
  9.         var b = a.extend({verdects:["Muito fraca","Fraca","Média","Forte","Muito forte"],colors:["#f00","#c06","#f60","#3c0","#3d0"],scores:[10,15,30,40],common:["password","sex","god","123456","123","liverpool","letmein","qwerty","monkey"],minchar:5}, b);
  10.         return this.each(function() {
  11.             var d = a(this).attr("id");
  12.             var c = '<div id="pstrength"><div class="pstrength-minchar" id="' + d + '_minchar"></div><div class="pstrength-info" id="' + d + '_text"></div><div class="pstrength-bar" id="' + d + '_bar" style="border: 1px solid white; font-size: 1px; height: 5px; width: 0px;"></div></div>';
  13.             a(this).after(c);
  14.             a(this).keyup(function() {
  15.                 a.fn.runPassword(a(this).val(), d, b)
  16.             })
  17.         })
  18.     },runPassword:function(d, b, e) {
  19.         nPerc = a.fn.checkPassword(d, e);
  20.         var f = "#" + b + "_bar";
  21.         var c = "#" + b + "_text";
  22.         if (nPerc == -200) {
  23.             strColor = "#f00";
  24.             strText = "Senha insegura!";
  25.             a(f).css({width:"0%"})
  26.         } else {
  27.             if (nPerc < 0 && nPerc > -199) {
  28.                 strColor = "#ccc";
  29.                 strText = "Muito pequena";
  30.                 a(f).css({width:"5%"})
  31.             } else {
  32.                 if (nPerc <= e.scores[0]) {
  33.                     strColor = e.colors[0];
  34.                     strText = e.verdects[0];
  35.                     a(f).css({width:"10%"})
  36.                 } else {
  37.                     if (nPerc > e.scores[0] && nPerc <= e.scores[1]) {
  38.                         strColor = e.colors[1];
  39.                         strText = e.verdects[1];
  40.                         a(f).css({width:"25%"})
  41.                     } else {
  42.                         if (nPerc > e.scores[1] && nPerc <= e.scores[2]) {
  43.                             strColor = e.colors[2];
  44.                             strText = e.verdects[2];
  45.                             a(f).css({width:"50%"})
  46.                         } else {
  47.                             if (nPerc > e.scores[2] && nPerc <= e.scores[3]) {
  48.                                 strColor = e.colors[3];
  49.                                 strText = e.verdects[3];
  50.                                 a(f).css({width:"75%"})
  51.                             } else {
  52.                                 strColor = e.colors[4];
  53.                                 strText = e.verdects[4];
  54.                                 a(f).css({width:"92%"})
  55.                             }
  56.                         }
  57.                     }
  58.                 }
  59.             }
  60.         }
  61.         a(f).css({backgroundColor:strColor});
  62.         a(c).html("<span style='color: " + strColor + ";'>" + strText + "</span>")
  63.     },checkPassword:function(e, f) {
  64.         var b = 0;
  65.         var c = f.verdects[0];
  66.         if (e.length < f.minchar) {
  67.             b = (b - 100)
  68.         } else {
  69.             if (e.length >= f.minchar && e.length <= (f.minchar + 2)) {
  70.                 b = (b + 6)
  71.             } else {
  72.                 if (e.length >= (f.minchar + 3) && e.length <= (f.minchar + 4)) {
  73.                     b = (b + 12)
  74.                 } else {
  75.                     if (e.length >= (f.minchar + 5)) {
  76.                         b = (b + 18)
  77.                     }
  78.                 }
  79.             }
  80.         }
  81.         if (e.match(/[a-z]/)) {
  82.             b = (b + 1)
  83.         }
  84.         if (e.match(/[A-Z]/)) {
  85.             b = (b + 5)
  86.         }
  87.         if (e.match(/\d+/)) {
  88.             b = (b + 5)
  89.         }
  90.         if (e.match(/(.*[0-9].*[0-9].*[0-9])/)) {
  91.             b = (b + 7)
  92.         }
  93.         if (e.match(/.[!,@,#,$,%,^,&,*,?,_,~]/)) {
  94.             b = (b + 5)
  95.         }
  96.         if (e.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) {
  97.             b = (b + 7)
  98.         }
  99.         if (e.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) {
  100.             b = (b + 2)
  101.         }
  102.         if (e.match(/([a-zA-Z])/) && e.match(/([0-9])/)) {
  103.             b = (b + 3)
  104.         }
  105.         if (e.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/)) {
  106.             b = (b + 3)
  107.         }
  108.         for (var d = 0; d < f.common.length; d++) {
  109.             if (e.toLowerCase() == f.common[d]) {
  110.                 b = -200
  111.             }
  112.         }
  113.         return b
  114.     }})
  115. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement