Tracking report should obey MaxCharactersInDisplayedSQL
[phpmyadmin/madhuracj.git] / js / server_privileges.js
blob3495e030492cfdf8384c8036c3d3535453f65e8a
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 and copy it to the password input areas
75  *
76  * @param   object   the form that holds the password fields
77  *
78  * @return  boolean  always true
79  */
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;
87     passwd.value = '';
89     for ( i = 0; i < passwordlength; i++ ) {
90         passwd.value += pwchars.charAt( Math.floor( Math.random() * pwchars.length ) )
91     }
92     passwd_form.text_pma_pw.value = passwd.value;
93     passwd_form.text_pma_pw2.value = passwd.value;
94     return true;