]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Users/PasswordRequirementBox.js
Release 6.5.0
[Github/sugarcrm.git] / 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 function password_confirmation(){var new_pwd=document.getElementById('new_password').value;var old_pwd=document.getElementById('old_password').value;var confirm_pwd=document.getElementById('confirm_pwd');if(confirm_pwd.value!=new_pwd)
36 confirm_pwd.style.borderColor='red';else
37 confirm_pwd.style.borderColor='';if(confirm_pwd.value!=(new_pwd.substring(0,confirm_pwd.value.length)))
38 document.getElementById('comfirm_pwd_match').style.display='inline';else
39 document.getElementById('comfirm_pwd_match').style.display='none';if(new_pwd!=""||confirm_pwd.value!=""||old_pwd!=""||(document.getElementById('page')&&document.getElementById('page').value=="Change"))
40 document.getElementById('password_change').value='true';else
41 document.getElementById('password_change').value='false';}
42 function set_password(form,rules){if(form.password_change.value=='true'){if(rules=='1'){alert(ERR_RULES_NOT_MET);return false;}
43 if(form.is_admin.value!=1&&(form.is_current_admin&&form.is_current_admin.value!='1')&&form.old_password.value==""){alert(ERR_ENTER_OLD_PASSWORD);return false;}
44 if(form.new_password.value==""){alert(ERR_ENTER_NEW_PASSWORD);return false;}
45 if(form.confirm_pwd.value==""){alert(ERR_ENTER_CONFIRMATION_PASSWORD);return false;}
46 if(form.new_password.value==form.confirm_pwd.value)
47 return true;else{alert(ERR_REENTER_PASSWORDS);return false;}}
48 else
49 return true;}
50 function newrules(minpwdlength,maxpwdlength,customregex){var good_rules=0;var passwd=document.getElementById('new_password').value;if(document.getElementById('lengths')){var length=document.getElementById('new_password').value.length;if((length<parseInt(minpwdlength)&&parseInt(minpwdlength)>0)||(length>parseInt(maxpwdlength)&&parseInt(maxpwdlength)>0)){document.getElementById('lengths').className='bad';good_rules=1;}
51 else{document.getElementById('lengths').className='good';}}
52 if(document.getElementById('1lowcase')){if(!passwd.match('[abcdefghijklmnopqrstuvwxyz]')){document.getElementById('1lowcase').className='bad';good_rules=1;}
53 else{document.getElementById('1lowcase').className='good';}}
54 if(document.getElementById('1upcase')){if(!passwd.match('[ABCDEFGHIJKLMNOPQRSTUVWXYZ]')){document.getElementById('1upcase').className='bad';good_rules=1;}
55 else{document.getElementById('1upcase').className='good';}}
56 if(document.getElementById('1number')){if(!passwd.match('[0123456789]')){document.getElementById('1number').className='bad';good_rules=1;}
57 else{document.getElementById('1number').className='good';}}
58 if(document.getElementById('1special')){var custom_regex=new RegExp('[|}{~!@#$%^&*()_+=-]');if(!custom_regex.test(passwd)){document.getElementById('1special').className='bad';good_rules=1;}
59 else{document.getElementById('1special').className='good';}}
60 if(document.getElementById('regex')){var regex=new RegExp(customregex);if(regex.test(passwd)){document.getElementById('regex').className='bad';good_rules=1;}
61 else{document.getElementById('regex').className='good';}}
62 return good_rules;}
63 function set_focus(){if(document.getElementById('error_pwd')){if(document.forms.length>0){for(i=0;i<document.forms.length;i++){for(j=0;j<document.forms[i].elements.length;j++){var field=document.forms[i].elements[j];if((field.type=="password")&&(field.name=="old_password")){field.focus();if(field.type=="text"){field.select();}
64 break;}}}}}
65 else{if(document.forms.length>0){for(i=0;i<document.forms.length;i++){for(j=0;j<document.forms[i].elements.length;j++){var field=document.forms[i].elements[j];if((field.type=="text"||field.type=="textarea"||field.type=="password")&&!field.disabled&&(field.name=="first_name"||field.name=="name"||field.name=="user_name"||field.name=="document_name")){field.focus();if(field.type=="text"){field.select();}
66 break;}}}}}}