PageSourceSearch

https://kulturportal.de/module/jscript/lib/jquery_plugins/pstrength.js

js kulturportal.de collected 2026-09-24 22:22:46 UTC 5,240 bytes, 126 lines download raw bytes

1//TODO save points in attribute
2window.pStrengthOptions = window.pStrengthOptions || {};
3pStrengthOptions.password = {
4   'keyupHandler' : function () {
5         pStrengthOptions.password.calculateScore(jQuery(this).val(),jQuery(this));
6   }, 'defaults' : {
7      'minChar': 5,
8      'colors': ["#f16e30", "#f9b45b", "#f9d877", "#f0f480", "#bbe268", "#81cb4d"],
9      'scores': [2, 3, 3, 5, 7, 8],
10      'raisePower': 0
11   },'ruleScores' : {
12      'length': 0,
13      'lowercase': 2,
14      'uppercase': 2,
15      'one_number': 3,
16      'three_numbers': 5,
17      'one_special_char': 3,
18      'two_special_char': 5,
19      'upper_lower_combo': 2,
20      'letter_number_combo': 3,
21      'letter_number_char_combo': 2
22   },'rules' : {
23      'length': true,
24      'lowercase': false,
25      'uppercase': false,
26      'one_number': false,
27      'three_numbers': false,
28      'one_special_char': true,
29      'two_special_char': false,
30      'upper_lower_combo': true,
31      'letter_number_combo': true,
32      'letter_number_char_combo': false
33   },'validationRules': {
34      'length': function (word, score) {
35         pStrengthOptions.password.tooShort = false;
36         var wordlen = word.length;
37         var lenScore = Math.pow(wordlen, pStrengthOptions.password.options.raisePower);
38         if (wordlen < pStrengthOptions.password.options.minChar) {
39            lenScore = (lenScore - 100);
40            pStrengthOptions.password.tooShort = true;
41         }
42         return lenScore;
43      },'lowercase': function (word, score) {
44         return word.match(/[a-z]/) && score;
45      },'uppercase': function (word, score) {
46         return word.match(/[A-Z]/) && score;
47      },'one_number': function (word, score) {
48         return word.match(/\d+/) && score;
49      },'three_numbers': function (word, score) {
50         return word.match(/(.*[0-9].*[0-9].*[0-9])/) && score;
51      },'one_special_char': function (word, score) {
52         return word.match(/.[!,@,#,$,%,\^,&,*,?,_,~]/) && score;
53      },'two_special_char': function (word, score) {
54         return word.match(/(.*[!,@,#,$,%,\^,&,*,?,_,~].*[!,@,#,$,%,\^,&,*,?,_,~])/) && score;
55      },'upper_lower_combo': function (word, score) {
56         return word.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/) && score;
57      },'letter_number_combo': function (word, score) {
58         return word.match(/([a-zA-Z])/) && word.match(/([0-9])/) && score;
59      },'letter_number_char_combo' : function (word, score) {
60         return word.match(/([a-zA-Z0-9].*[!,@,#,$,%,\^,&,*,?,_,~])|([!,@,#,$,%,\^,&,*,?,_,~].*[a-zA-Z0-9])/) && score;
61      }
62   },'attachWidget': function (element) {
63   },'addRule': function (name, method, score, active) {
64      pStrengthOptions.password.rules[name] = active;
65      pStrengthOptions.password.ruleScores[name] = score;
66      pStrengthOptions.password.validationRules[name] = method;
67      return true;
68   },'init': function (element, options) {
69      pStrengthOptions.password.options = jQuery.extend({}, pStrengthOptions.password.defaults, options);
70      pStrengthOptions.password.attachWidget(element);
71      jQuery(element).keyup(pStrengthOptions.password.keyupHandler);
72   },'destroy': function (element) {
73      jQuery(element).unbind('keyup', pStrengthOptions.password.keyupHandler)
74   },'calculateScore': function (word,usedInputBox) {
75      pStrengthOptions.password.totalscore = 0;
76      pStrengthOptions.password.width = 0;
77      for (var key in pStrengthOptions.password.rules) if (pStrengthOptions.password.rules.hasOwnProperty(key)) {
78         if (pStrengthOptions.password.rules[key] === true) {
79            var score = pStrengthOptions.password.ruleScores[key];
80            var result = pStrengthOptions.password.validationRules[key](word, score);
81            if (result) {
82               pStrengthOptions.password.totalscore += result;
83            }
84         }
85         var bgColor = '';
86         var scores = pStrengthOptions.password.options.scores;
87         var total = pStrengthOptions.password.totalscore;
88         var colors = pStrengthOptions.password.options.colors;
89         if (total <= scores[0])
90            bgColor = colors[0];
91         else {
92            for (var i=0; i < (scores.length-1); i++) {
93               if (total > scores[i] && total <= scores[(i+1)]) {
94                  bgColor = colors[(i+1)];
95               }
96            }
97         }
98         if (bgColor == '')
99            bgColor = colors[(colors.length-1)];
100         jQuery(usedInputBox).css({'background-color': bgColor});
101      }
102   }
103};
104jQuery.extend(jQuery.fn, {
105   'pstrength': function (options) {
106      return this.each(function () {
107         if (options === 'destroy') {
108            pStrengthOptions.password.destroy(this);
109         } else {
110            pStrengthOptions.password.init(this, options);
111         }
112      });
113   }
114});
115jQuery.extend(jQuery.fn.pstrength, {
116   'addRule': function (name, method, score, active) {
117      pStrengthOptions.password.addRule(name, method, score, active);
118      return true;
119   },'changeScore': function (rule, score) {
120      pStrengthOptions.password.ruleScores[rule] = score;
121      return true;
122   },'ruleActive': function (rule, active) {
123      pStrengthOptions.password.rules[rule] = active;
124      return true;
125   }
126});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.