]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/modules/Users/PasswordRequirementBox.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / modules / Users / PasswordRequirementBox.js
1 /*********************************************************************************
2  * SugarCRM Community Edition is a customer relationship management program developed by
3  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
4  * 
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU Affero General Public License version 3 as published by the
7  * Free Software Foundation with the addition of the following permission added
8  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
9  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
10  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
11  * 
12  * This program is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
15  * details.
16  * 
17  * You should have received a copy of the GNU Affero General Public License along with
18  * this program; if not, see http://www.gnu.org/licenses or write to the Free
19  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301 USA.
21  * 
22  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
23  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
24  * 
25  * The interactive user interfaces in modified source and object code versions
26  * of this program must display Appropriate Legal Notices, as required under
27  * Section 5 of the GNU Affero General Public License version 3.
28  * 
29  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
30  * these Appropriate Legal Notices must retain the display of the "Powered by
31  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
32  * technical reasons, the Appropriate Legal Notices must display the words
33  * "Powered by SugarCRM".
34  ********************************************************************************/
35
36
37 function password_confirmation() {
38     var new_pwd=document.getElementById('new_password').value;
39     var old_pwd=document.getElementById('old_password').value;
40     var confirm_pwd=document.getElementById('confirm_pwd');
41     if (confirm_pwd.value != new_pwd)
42         confirm_pwd.style.borderColor= 'red';
43     else
44         confirm_pwd.style.borderColor='';
45     
46     if (confirm_pwd.value != (new_pwd.substring(0,confirm_pwd.value.length)))
47         document.getElementById('comfirm_pwd_match').style.display = 'inline';
48     else
49         document.getElementById('comfirm_pwd_match').style.display = 'none';
50         
51     if (new_pwd != "" || confirm_pwd.value != "" || old_pwd !="" || (document.getElementById('page') && document.getElementById('page').value=="Change"))       
52         document.getElementById('password_change').value = 'true';
53     else
54         document.getElementById('password_change').value = 'false';
55 }
56
57 function set_password(form,rules) {
58         if(form.password_change.value == 'true'){
59         if( rules=='1'){
60                 alert(ERR_RULES_NOT_MET);
61                 return false;
62         }
63         
64                 if (form.is_admin.value != 1 && (form.is_current_admin && form.is_current_admin.value != '1')&& form.old_password.value == "" ){
65                         alert(ERR_ENTER_OLD_PASSWORD);
66                         return false;
67                 }
68                 
69                 if (form.new_password.value == "" ) {
70                         alert(ERR_ENTER_NEW_PASSWORD);
71                         return false;
72                 }
73                 
74                 if (form.confirm_pwd.value == ""){
75                         alert(ERR_ENTER_CONFIRMATION_PASSWORD);
76                         return false;
77                 }
78                 
79                 if (form.new_password.value == form.confirm_pwd.value)
80                         return true;
81                 else{
82                         alert(ERR_REENTER_PASSWORDS);
83                         return false;
84                 }
85         }
86         else
87                 return true;
88 }
89   
90     function newrules(minpwdlength,maxpwdlength,customregex){
91     var good_rules=0;               
92     var passwd = document.getElementById('new_password').value;
93         // length
94         if(document.getElementById('lengths')){
95                 var length =document.getElementById('new_password').value.length;
96                 if((length < parseInt(minpwdlength) && parseInt(minpwdlength)>0)  || (length > parseInt(maxpwdlength) && parseInt(maxpwdlength)>0 )){
97                     document.getElementById('lengths').className='bad';
98                     good_rules=1;
99                 }
100                 else{document.getElementById('lengths').className='good';}
101         }
102        
103         // One lower case
104         if(document.getElementById('1lowcase')){
105                 if(!passwd.match('[abcdefghijklmnopqrstuvwxyz]')){
106                     document.getElementById('1lowcase').className='bad';
107                     good_rules=1;
108                 }
109                 else{document.getElementById('1lowcase').className='good';}
110         }
111         
112         // One upper case
113         if(document.getElementById('1upcase')){
114                 if(!passwd.match('[ABCDEFGHIJKLMNOPQRSTUVWXYZ]')){
115                     document.getElementById('1upcase').className='bad';
116                     good_rules=1;
117                 }
118                 else{document.getElementById('1upcase').className='good';}
119         }
120         
121         // One number
122         if(document.getElementById('1number')){
123                 if(!passwd.match('[0123456789]')){
124                     document.getElementById('1number').className='bad';
125                     good_rules=1;
126                 }
127                 else{document.getElementById('1number').className='good';}
128         }
129         
130         // One special character
131         if(document.getElementById('1special')){
132             var custom_regex= new RegExp('[|}{~!@#$%^&*()_+=-]');
133                 if(!custom_regex.test(passwd)){
134                     document.getElementById('1special').className='bad';
135                     good_rules=1;
136                 }
137                 else{document.getElementById('1special').className='good';}
138         }
139         
140         
141         // Custom regex
142         if(document.getElementById('regex')){
143             var regex = new RegExp(customregex);
144                 if(regex.test(passwd)){
145                     document.getElementById('regex').className='bad';
146                     good_rules=1;
147                 }
148                 else{document.getElementById('regex').className='good';}
149         }
150     return good_rules;
151     } 
152     
153         
154 function set_focus() {
155     if (document.getElementById('error_pwd')){
156         if (document.forms.length > 0) {
157             for (i = 0; i < document.forms.length; i++) {
158                 for (j = 0; j < document.forms[i].elements.length; j++) {
159                     var field = document.forms[i].elements[j];
160                     if ((field.type == "password") && (field.name == "old_password" )) {
161                         field.focus();
162                         if (field.type == "text") {
163                             field.select();
164                         }
165                         break;
166                     }
167                 }
168             }
169         } 
170     }
171     else{
172         if (document.forms.length > 0) {
173             for (i = 0; i < document.forms.length; i++) {
174                 for (j = 0; j < document.forms[i].elements.length; j++) {
175                     var field = document.forms[i].elements[j];
176                     if ((field.type == "text" || field.type == "textarea" || field.type == "password") &&
177                             !field.disabled && (field.name == "first_name" || field.name == "name" || field.name == "user_name" || field.name=="document_name")) {
178                         field.focus();
179                         if (field.type == "text") {
180                             field.select();
181                         }
182                         break;
183                     }
184                 }
185             }
186         }
187     }
188 }