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 and copy it to the password input areas
76 * @param object the form that holds the password fields
78 * @return boolean always true
80 function suggestPassword(passwd_form) {
81 // restrict the password to just letters and numbers to avoid problems:
82 // "editors and viewers regard the password as multiple words and
83 // things like double click no longer work"
84 var pwchars = "abcdefhjmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWYXZ";
85 var passwordlength = 16; // do we want that to be dynamic? no, keep it simple :)
86 var passwd = passwd_form.generated_pw;
89 for ( i = 0; i < passwordlength; i++ ) {
90 passwd.value += pwchars.charAt( Math.floor( Math.random() * pwchars.length ) )
92 passwd_form.text_pma_pw.value = passwd.value;
93 passwd_form.text_pma_pw2.value = passwd.value;