patch #2541261, improvement to patch #2506831
[phpmyadmin/crack.git] / js / server_privileges.js
blobac9396d8664951b4e60eb8d756343bf4f96344f9
1 /* vim: set expandtab sw=4 ts=4 sts=4: */
2 /**
3  * function used in server privilege pages
4  *
5  * @version $Id$
6  */
8 /**
9  * Validates the password field in a form
10  *
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
15  */
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) {
21         return true;
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')) {
25         return true;
26     }
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'];
36     }
38     if (alert_msg) {
39         alert(alert_msg);
40         password.value  = '';
41         password_repeat.value = '';
42         password.focus();
43         return false;
44     }
46     return true;
47 } // end of the 'checkPassword()' function
50 /**
51  * Validates the "add a user" form
52  *
53  * @return  boolean  whether the form is validated or not
54  */
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();
60         return false;
61     }
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();
66         return false;
67     }
69     return checkPassword(the_form);
70 } // end of the 'checkAddUser()' function
73 /**
74  * Generate a new password, which may then be copied to the form
75  * with suggestPasswordCopy().
76  *
77  * @param   string   the form name
78  *
79  * @return  boolean  always true
80  */
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');
88     passwd.value = '';
90     for ( i = 0; i < passwordlength; i++ ) {
91         passwd.value += pwchars.charAt( Math.floor( Math.random() * pwchars.length ) )
92     }
93     return passwd.value;
97 /**
98  * Copy the generated password (or anything in the field) to the form
99  *
100  * @param   string   the form name
102  * @return  boolean  always true
103  */
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;
107     return true;