Guest User

Untitled

a guest
Mar 10th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. document.oncontextmenu=function(){return false;}
  2. $(document).bind('mousedown.disableTextSelect', function() {return false;});
  3.  
  4. /*
  5.     Password Validator 0.1
  6.     (c) 2007 Steven Levithan <stevenlevithan.com>
  7.     MIT License
  8. */
  9.  
  10. function validatePassword (pw, options) {
  11.     // default options (allows any password)
  12.     var o = {
  13.         lower:    0,
  14.         upper:    0,
  15.         alpha:    0, /* lower + upper */
  16.         numeric:  0,
  17.         special:  0,
  18.         length:   [0, Infinity],
  19.         custom:   [ /* regexes and/or functions */ ],
  20.         badWords: [],
  21.         badSequenceLength: 0,
  22.         noQwertySequences: false,
  23.         noSequential:      false
  24.     };
  25.  
  26.     for (var property in options)
  27.         o[property] = options[property];
  28.  
  29.     var re = {
  30.             lower:   /[a-z]/g,
  31.             upper:   /[A-Z]/g,
  32.             alpha:   /[A-Z]/gi,
  33.             numeric: /[0-9]/g,
  34.             special: /[\W_]/g
  35.         },
  36.         rule, i;
  37.  
  38.     // enforce min/max length
  39.     if (pw.length < o.length[0] || pw.length > o.length[1])
  40.         return false;
  41.  
  42.     // enforce lower/upper/alpha/numeric/special rules
  43.     for (rule in re) {
  44.         if ((pw.match(re[rule]) || []).length < o[rule])
  45.             return false;
  46.     }
  47.  
  48.     // enforce word ban (case insensitive)
  49.     for (i = 0; i < o.badWords.length; i++) {
  50.         if (pw.toLowerCase().indexOf(o.badWords[i].toLowerCase()) > -1)
  51.             return false;
  52.     }
  53.  
  54.     // enforce the no sequential, identical characters rule
  55.     if (o.noSequential && /([\S\s])\1/.test(pw))
  56.         return false;
  57.  
  58.     // enforce alphanumeric/qwerty sequence ban rules
  59.     if (o.badSequenceLength) {
  60.         var lower   = "abcdefghijklmnopqrstuvwxyz",
  61.             upper   = lower.toUpperCase(),
  62.             numbers = "0123456789",
  63.             qwerty  = "qwertyuiopasdfghjklzxcvbnm",
  64.             start   = o.badSequenceLength - 1,
  65.             seq     = "_" + pw.slice(0, start);
  66.         for (i = start; i < pw.length; i++) {
  67.             seq = seq.slice(1) + pw.charAt(i);
  68.             if (
  69.                 lower.indexOf(seq)   > -1 ||
  70.                 upper.indexOf(seq)   > -1 ||
  71.                 numbers.indexOf(seq) > -1 ||
  72.                 (o.noQwertySequences && qwerty.indexOf(seq) > -1)
  73.             ) {
  74.                 return false;
  75.             }
  76.         }
  77.     }
  78.  
  79.     // enforce custom regex/function rules
  80.     for (i = 0; i < o.custom.length; i++) {
  81.         rule = o.custom[i];
  82.         if (rule instanceof RegExp) {
  83.             if (!rule.test(pw))
  84.                 return false;
  85.         } else if (rule instanceof Function) {
  86.             if (!rule(pw))
  87.                 return false;
  88.         }
  89.     }
  90.  
  91.     // great success!
  92.     return true;
  93. }
  94.  
  95. var password = "P@śsw0rd";
  96. var passed = validatePassword(password, {
  97.     length:   [8, Infinity],
  98.     lower:    1,
  99.     upper:    1,
  100.     numeric:  1,
  101.     special:  1,
  102.     badWords: ["password", "steven", "levithan"],
  103.     badSequenceLength: 4
  104. });
  105.  
  106. passed;
Add Comment
Please, Sign In to add comment