1 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 * function used in server privilege pages
9 * Validates the password field in a form
11 * @uses PMA_messages['strPasswordEmpty']
12 * @uses PMA_messages['strPasswordNotSame']
13 * @param object the form
14 * @return boolean whether the field value is valid or not
16 function checkPassword(the_form
)
18 // Did the user select 'no password'?
19 if (typeof(the_form
.elements
['nopass']) != 'undefined'
20 && the_form
.elements
['nopass'][0].checked
) {
22 } else if (typeof(the_form
.elements
['pred_password']) != 'undefined'
23 && (the_form
.elements
['pred_password'].value
== 'none'
24 || the_form
.elements
['pred_password'].value
== 'keep')) {
28 var password
= the_form
.elements
['pma_pw'];
29 var password_repeat
= the_form
.elements
['pma_pw2'];
30 var alert_msg
= false;
32 if (password
.value
== '') {
33 alert_msg
= PMA_messages
['strPasswordEmpty'];
34 } else if (password
.value
!= password_repeat
.value
) {
35 alert_msg
= PMA_messages
['strPasswordNotSame'];
41 password_repeat
.value
= '';
47 } // end of the 'checkPassword()' function
51 * Validates the "add a user" form
53 * @return boolean whether the form is validated or not
55 function checkAddUser(the_form
)
57 if (the_form
.elements
['pred_hostname'].value
== 'userdefined' && the_form
.elements
['hostname'].value
== '') {
58 alert(PMA_messages
['strHostEmpty']);
59 the_form
.elements
['hostname'].focus();
63 if (the_form
.elements
['pred_username'].value
== 'userdefined' && the_form
.elements
['username'].value
== '') {
64 alert(PMA_messages
['strUserEmpty']);
65 the_form
.elements
['username'].focus();
69 return checkPassword(the_form
);
70 } // end of the 'checkAddUser()' function
74 * Generate a new password, which may then be copied to the form
75 * with suggestPasswordCopy().
77 * @param string the form name
79 * @return boolean always true
81 function suggestPassword() {
82 // restrict the password to just letters and numbers to avoid problems:
83 // "editors and viewers regard the password as multiple words and
84 // things like double click no longer work"
85 var pwchars
= "abcdefhjmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWYXZ";
86 var passwordlength
= 16; // do we want that to be dynamic? no, keep it simple :)
87 var passwd
= document
.getElementById('generated_pw');
90 for ( i
= 0; i
< passwordlength
; i
++ ) {
91 passwd
.value
+= pwchars
.charAt( Math
.floor( Math
.random() * pwchars
.length
) )
98 * Copy the generated password (or anything in the field) to the form
100 * @param string the form name
102 * @return boolean always true
104 function suggestPasswordCopy() {
105 document
.getElementById('text_pma_pw').value
= document
.getElementById('generated_pw').value
;
106 document
.getElementById('text_pma_pw2').value
= document
.getElementById('generated_pw').value
;