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 var pwchars = "abcdefhjmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWYXZ.,:";
83 var passwordlength = 16; // do we want that to be dynamic? no, keep it simple :)
84 var passwd = document.getElementById('generated_pw');
87 for ( i = 0; i < passwordlength; i++ ) {
88 passwd.value += pwchars.charAt( Math.floor( Math.random() * pwchars.length ) )
95 * Copy the generated password (or anything in the field) to the form
97 * @param string the form name
99 * @return boolean always true
101 function suggestPasswordCopy() {
102 document.getElementById('text_pma_pw').value = document.getElementById('generated_pw').value;
103 document.getElementById('text_pma_pw2').value = document.getElementById('generated_pw').value;