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 * @param object the form
13 * @return boolean whether the field value is valid or not
15 function checkPassword(the_form)
17 // Did the user select 'no password'?
18 if (typeof(the_form.elements['nopass']) != 'undefined' && the_form.elements['nopass'][0].checked) {
20 } else if (typeof(the_form.elements['pred_password']) != 'undefined' && (the_form.elements['pred_password'].value == 'none' || the_form.elements['pred_password'].value == 'keep')) {
25 if (the_form.elements['pma_pw'].value == '') {
26 alert(jsPasswordEmpty);
27 the_form.elements['pma_pw2'].value = '';
28 the_form.elements['pma_pw'].focus();
30 } else if (the_form.elements['pma_pw'].value != the_form.elements['pma_pw2'].value) {
31 alert(jsPasswordNotSame);
32 the_form.elements['pma_pw'].value = '';
33 the_form.elements['pma_pw2'].value = '';
34 the_form.elements['pma_pw'].focus();
39 } // end of the 'checkPassword()' function
43 * Validates the "add a user" form
45 * @return boolean whether the form is validated or not
47 function checkAddUser(the_form)
49 if (the_form.elements['pred_hostname'].value == 'userdefined' && the_form.elements['hostname'].value == '') {
51 the_form.elements['hostname'].focus();
55 if (the_form.elements['pred_username'].value == 'userdefined' && the_form.elements['username'].value == '') {
57 the_form.elements['username'].focus();
61 return checkPassword(the_form);
62 } // end of the 'checkAddUser()' function
66 * Generate a new password, which may then be copied to the form
67 * with suggestPasswordCopy().
69 * @param string the form name
71 * @return boolean always true
73 function suggestPassword() {
74 // restrict the password to just letters and numbers to avoid problems:
75 // "editors and viewers regard the password as multiple words and
76 // things like double click no longer work"
77 var pwchars = "abcdefhjmnpqrstuvwxyz23456789ABCDEFGHJKLMNPQRSTUVWYXZ";
78 var passwordlength = 16; // do we want that to be dynamic? no, keep it simple :)
79 var passwd = document.getElementById('generated_pw');
82 for ( i = 0; i < passwordlength; i++ ) {
83 passwd.value += pwchars.charAt( Math.floor( Math.random() * pwchars.length ) )
90 * Copy the generated password (or anything in the field) to the form
92 * @param string the form name
94 * @return boolean always true
96 function suggestPasswordCopy() {
97 document.getElementById('text_pma_pw').value = document.getElementById('generated_pw').value;
98 document.getElementById('text_pma_pw2').value = document.getElementById('generated_pw').value;