Dodan patch za podesavanje $min_pass_length vrijednosti.
[squirrelmail-change-pass.git] / options.php
1 <?php
2
3 /*
4  * Licensed under the GNU GPL. For full terms see the file COPYING.
5  *
6  * $Id: options.php,v 1.7 2009/05/05 03:09:22 indiri69 Exp $
7  */
8
9 define('SM_PATH', '../../');
10 require_once(SM_PATH . 'include/validate.php');
11 require_once(SM_PATH . 'functions/html.php');
12 require_once(SM_PATH . 'functions/forms.php');
13
14 $debug = false;
15
16 // Make sure the plugin is activated
17 global $plugins;
18 if(!in_array('change_pass', $plugins)) {
19     exit;
20 }
21
22 $min_pass_length = 0;
23 $max_pass_length = 99999999;
24
25 if (!@include(SM_PATH . 'config/config_change_pass.php')) {
26      @include(SM_PATH . 'plugins/change_pass/config.php');
27 }
28
29 include_once(SM_PATH . 'plugins/change_pass/functions.php');
30
31 global $color;
32 sqgetGlobalVar('change_pass_form', $change_pass_form, SQ_POST);
33
34 $error_messages = array();
35 $showform = true;
36
37 if (isset($change_pass_form)) {
38     sq_change_text_domain('change_pass');
39     sqgetGlobalVar('change_pass_old', $change_pass_old, SQ_POST);
40     sqgetGlobalVar('change_pass_new', $change_pass_new, SQ_POST);
41     sqgetGlobalVar('change_pass_verify', $change_pass_verify, SQ_POST);
42
43     if(!isset($change_pass_old) || $change_pass_old == '') {
44         $error_messages['cp_no_old'] = _("You must type in your current password.");
45     }
46
47     if(!isset($change_pass_new) || $change_pass_new == '') {
48         $error_messages['cp_no_new'] = _("You must type in a new password.");
49     }
50
51     if(!isset($change_pass_verify) || $change_pass_verify == '') {
52         $error_messages['cp_no_verify'] = _("You must also type in your new password in the verify box.");
53     }
54
55     if(!isset($error_messages['cp_no_new']) && !isset($error_messages['cp_no_verify'])) {
56         if($change_pass_new != $change_pass_verify) {
57             $error_messages['cp_new_mismatch'] = _("Your new password does not match the verify password.");
58         } else {
59             if (strlen($change_pass_new) < $min_pass_length ||
60                 strlen($change_pass_new) > $max_pass_length) {
61                     $error_messages[] = sprintf(_("Your new password should be %s to %s characters long."),
62                                                 $min_pass_length, $max_pass_length);
63             }
64         }
65     }
66
67     $old_pass = sqauth_read_password();
68     if(!isset($error_messages['cp_no_old']) && $change_pass_old != $old_pass) {
69         $error_messages['cp_wrong_old'] = _("Your current password is not correct.");
70     }
71
72     if(count($error_messages) == 0) {
73         $error_messages = change_pass_dochange($change_pass_old, $change_pass_new, $debug);
74         if(count($error_messages) == 0) {
75             $showform = false;
76         }
77     }
78     sq_change_text_domain('squirrelmail');
79 }
80 displayPageHeader($color, '');
81 sq_change_text_domain('change_pass');
82
83 echo
84     html_tag('table', "\n" .
85         html_tag('tr', "\n" .
86             html_tag('td', '<b>' . _("Change Password") . '</b>', 'center', $color[0])
87         ),
88         'center', $color[9], 'width="95%" border="0" cellpadding="1" cellspacing="0"') . "<br>\n";
89
90 if(count($error_messages) > 0) {
91     echo html_tag('table', '', 'center', '', 'width="100%" border="0" cellpadding="1" cellspacing="0"');
92     echo html_tag('tr');
93     echo html_tag('td', '', 'center');
94     echo html_tag('ul');
95     foreach($error_messages as $line) {
96         echo html_tag('li', htmlspecialchars($line), '', '', 'style="color: ' . $color[2] . '"');
97     }
98     echo html_tag('/ul');
99     echo html_tag('tr', html_tag('td', '&nbsp;')) . "\n";
100     echo html_tag('/table');
101 }
102
103 if($showform) {
104     echo addForm($PHP_SELF);
105     echo
106         html_tag('table', "\n" .
107             html_tag('tr', "\n" .
108                 html_tag('td', _("Current Password:"), 'right') .
109                 html_tag('td', addPwField('change_pass_old', ''), 'left')
110             ) .
111             html_tag('tr', "\n" .
112                 html_tag('td', _("New Password:"), 'right') .
113                 html_tag('td', addPwField('change_pass_new', ''), 'left')
114             ) .
115             html_tag('tr', "\n" .
116                 html_tag('td', _("Verify New Password:"), 'right') .
117                 html_tag('td', addPwField('change_pass_verify', ''), 'left')
118             ) .
119             html_tag('tr', "\n" .
120                 html_tag('td', addSubmit(_('Change Password'), 'change_pass_form'), 'center', '', 'colspan="2"')
121             ),
122             'center', '', 'border="0" cellpadding="1" cellspacing="0"') . "\n";
123     echo html_tag('/form');
124     echo html_tag('/body');
125     echo html_tag('/html');
126 }
127 sq_change_text_domain('squirrelmail');