Code

Removed usePrototype flag, its activated always now.
[gosa.git] / gosa-core / html / include / pwdStrength.js
1 /*************************************************************
2 Created: 20060120
3 Author:  Steve Moitozo <god at zilla dot us>
4 Description: This is a quick and dirty password quality meter 
5                  written in JavaScript
6 License: MIT License (see below)
7 =================================
8 Revision Author: Dick Ervasti (dick dot ervasti at quty dot com)
9 Revision Description: Exchanged text based prompts for a graphic thermometer
10 =================================
11 Revision Author: Jay Bigam jayb <o> tearupyourlawn <o> com
12 Revision Date: Feb. 26, 2007
13 Revision Description: Changed D. Ervasti's table based "thermometer" to CSS.
14 Revision Notes: - Verified to work in FF2, IE7 and Safari2
15                 - Modified messages to reflect Minimum strength requirement
16                 - Added formSubmit button disabled until minimum requirement met
17 =================================
18 Modified: 20061111 - Steve Moitozo corrected regex for letters and numbers
19                      Thanks to Zack Smith -- zacksmithdesign.com
20                      and put MIT License back in
21 Modified: 20100201 - Cajus Pollmeier stripped parts unnessesary for GOsa and
22                      moved to prototype. Stripped comments.
23 ---------------------------------------------------------------
24 Copyright (c) 2006 Steve Moitozo <god at zilla dot us>
26 Permission is hereby granted, free of charge, to any person
27 obtaining a copy of this software and associated documentation
28 files (the "Software"), to deal in the Software without
29 restriction, including without limitation the rights to use,
30 copy, modify, merge, publish, distribute, sublicense, and/or
31 sell copies of the Software, and to permit persons to whom the
32 Software is furnished to do so, subject to the following
33 conditions:
35 The above copyright notice and this permission notice shall
36 be included in all copies or substantial portions of the
37 Software.
39 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
40 KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
41 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
42 AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
43 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
44 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
45 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
46 OR OTHER DEALINGS IN THE SOFTWARE.
47 ---------------------------------------------------------------
48  
49 ************************************************************ */
50 function testPasswordCss(passwd)
51 {
52                 var intScore   = 0
53                 
54                 // PASSWORD LENGTH
55                 if (passwd.length==0 || !passwd.length)                         // length 0
56                 {
57                         intScore = -1
58                 }
59                 else if (passwd.length>0 && passwd.length<5) // length between 1 and 4
60                 {
61                         intScore = (intScore+3)
62                 }
63                 else if (passwd.length>4 && passwd.length<8) // length between 5 and 7
64                 {
65                         intScore = (intScore+6)
66                 }
67                 else if (passwd.length>7 && passwd.length<12)// length between 8 and 15
68                 {
69                         intScore = (intScore+12)
70                 }
71                 else if (passwd.length>11)                    // length 16 or more
72                 {
73                         intScore = (intScore+18)
74                 }
75                 
76                 
77                 // LETTERS (Not exactly implemented as dictacted above because of my limited understanding of Regex)
78                 if (passwd.match(/[a-z]/))                              // [verified] at least one lower case letter
79                 {
80                         intScore = (intScore+1)
81                 }
82                 
83                 if (passwd.match(/[A-Z]/))                              // [verified] at least one upper case letter
84                 {
85                         intScore = (intScore+5)
86                 }
87                 
88                 // NUMBERS
89                 if (passwd.match(/\d+/))                                 // [verified] at least one number
90                 {
91                         intScore = (intScore+5)
92                 }
93                 
94                 if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/))             // [verified] at least three numbers
95                 {
96                         intScore = (intScore+5)
97                 }
98                 
99                 
100                 // SPECIAL CHAR
101                 if (passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/))            // [verified] at least one special character
102                 {
103                         intScore = (intScore+5)
104                 }
105                 
106                                                                                                                                  // [verified] at least two special characters
107                 if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/))
108                 {
109                         intScore = (intScore+5)
110                 }
111         
112                 
113                 // COMBOS
114                 if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))        // [verified] both upper and lower case
115                 {
116                         intScore = (intScore+2)
117                 }
119                 if (passwd.match(/([a-zA-Z])/) && passwd.match(/([0-9])/)) // [verified] both letters and numbers
120                 {
121                         intScore = (intScore+2)
122                 }
124                 // [verified] letters, numbers, and special characters
125                 if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/))
126                 {
127                         intScore = (intScore+2)
128                 }
130         
131                 if(intScore == -1)
132                 {
133                    $('meterEmpty').setStyle({width: '100%'});
134                    $('meterFull').setStyle({width: '0%'});
135                 }
136                 else if(intScore > -1 && intScore < 16)
137                 {
138                    $('meterEmpty').setStyle({width: '100%'});
139                    $('meterFull').setStyle({width: '0%'});
140                 }
141                 else if (intScore > 15 && intScore < 25)
142                 {
143                    $('meterEmpty').setStyle({width: '100%'});
144                    $('meterFull').setStyle({width: '25%'});
145                 }
146                 else if (intScore > 24 && intScore < 35)
147                 {
148                    $('meterEmpty').setStyle({width: '100%'});
149                    $('meterFull').setStyle({width: '50%'});
150                 }
151                 else if (intScore > 34 && intScore < 45)
152                 {
153                    $('meterEmpty').setStyle({width: '100%'});
154                    $('meterFull').setStyle({width: '75%'});
155                 }
156                 else
157                 {
158                    $('meterEmpty').setStyle({width: '100%'});
159                    $('meterFull').setStyle({width: '100%'});
160                 }