source: trunk/preferences/changepassword.php @ 32

Revision 32, 5.1 KB checked in by niltonneto, 17 years ago (diff)

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2        /**************************************************************************\
3        * phpGroupWare - preferences                                               *
4        * http://www.phpgroupware.org                                              *
5        * Written by Joseph Engo <jengo@phpgroupware.org>                          *
6        * --------------------------------------------                             *
7        *  This program is free software; you can redistribute it and/or modify it *
8        *  under the terms of the GNU General Public License as published by the   *
9        *  Free Software Foundation; either version 2 of the License, or (at your  *
10        *  option) any later version.                                              *
11        \**************************************************************************/
12
13
14        $GLOBALS['phpgw_info']['flags'] = array(
15                'noheader'   => True,
16                'nonavbar'   => True,
17                'currentapp' => 'preferences'
18        );
19
20        include('../header.inc.php');
21
22        $a_passwd   = $_POST['a_passwd'];
23        $n_passwd   = $_POST['n_passwd'];
24        $n_passwd_2 = $_POST['n_passwd_2'];
25
26        if(!$GLOBALS['phpgw']->acl->check('changepassword', 1) || $_POST['cancel'])
27        {
28                $GLOBALS['phpgw']->redirect_link('/preferences/index.php');
29                $GLOBALS['phpgw']->common->phpgw_exit();
30        }
31
32        $GLOBALS['phpgw']->template->set_file(array(
33                'form' => 'changepassword.tpl'
34        ));
35        $GLOBALS['phpgw']->template->set_var('lang_enter_actual_password',lang('Enter your actual password'));
36        $GLOBALS['phpgw']->template->set_var('lang_enter_password',lang('Enter your new password'));
37        $GLOBALS['phpgw']->template->set_var('lang_reenter_password',lang('Re-enter your password'));
38        $GLOBALS['phpgw']->template->set_var('lang_change',lang('Change'));
39        $GLOBALS['phpgw']->template->set_var('lang_cancel',lang('Cancel'));
40        $GLOBALS['phpgw']->template->set_var('form_action',$GLOBALS['phpgw']->link('/preferences/changepassword.php'));
41
42        if ($GLOBALS['phpgw_info']['server']['auth_type'] != 'ldap')
43        {
44                $GLOBALS['phpgw']->template->set_var('sql_message',lang('note: This feature does *not* change your email password. This will '
45                        . 'need to be done manually.'));
46        }
47
48        if ($_POST['change'])
49        {
50                if (! $GLOBALS['phpgw']->auth->authenticate($GLOBALS['phpgw_info']['user']['account_lid'], $a_passwd))
51                {
52                        $errors[] = lang('Your actual password is wrong');
53                }
54
55                if ($n_passwd != $n_passwd_2)
56                {
57                        $errors[] = lang('The two passwords are not the same');
58                }
59
60                if (! $n_passwd)
61                {
62                        $errors[] = lang('You must enter a password');
63                }
64               
65                // Default number of letters = 3
66                if (!$GLOBALS['phpgw_info']['server']['num_letters_userpass'])
67                        $GLOBALS['phpgw_info']['server']['num_letters_userpass'] = 3;
68                // Default number of special letters = 0
69                if (!$GLOBALS['phpgw_info']['server']['num_special_letters_userpass'])
70                        $GLOBALS['phpgw_info']['server']['num_special_letters_userpass'] = 0;
71
72                if ( strlen( $n_passwd ) < $GLOBALS['phpgw_info']['server']['num_letters_userpass'] )
73                {
74                        $errors[] = lang('Your password must contain %1 or more letters', $GLOBALS['phpgw_info']['server']['num_letters_userpass']);
75                }
76               
77                # password that start with a-Z or 0-9 and contain _.-!@#$%&*+=| will be accepted.
78                if (! ereg ("^([-a-zA-Z0-9_.\-!@#$%&*+=|])*$", $n_passwd ) )
79                {
80                        $errors[] = lang('Your password contains characters not allowed');
81                }
82               
83                # password must contain 2 special letters, numbers or special characters
84                if (! ereg ("([0-9_.\-!@#$%&*+=|]){".$GLOBALS['phpgw_info']['server']['num_special_letters_userpass'].",}", $n_passwd ) )
85                {
86                        $errors[] = lang('Your password must contain at least %1 numbers or characters special', $GLOBALS['phpgw_info']['server']['num_special_letters_userpass']);
87                }
88               
89                if(is_array($errors))
90                {
91                        $GLOBALS['phpgw']->common->phpgw_header();
92                        echo parse_navbar();
93                        $GLOBALS['phpgw']->template->set_var('messages',$GLOBALS['phpgw']->common->error_list($errors));
94                        $GLOBALS['phpgw']->template->pfp('out','form');
95                        $GLOBALS['phpgw']->common->phpgw_exit(True);
96                }
97
98                $o_passwd = $GLOBALS['phpgw_info']['user']['passwd'];
99                $passwd_changed = $GLOBALS['phpgw']->auth->change_password($o_passwd, $n_passwd);
100                if(!$passwd_changed)
101                {
102                        $errors[] = lang('Failed to change password.  Please contact your administrator.');
103                        $GLOBALS['phpgw']->common->phpgw_header();
104                        echo parse_navbar();
105                        $GLOBALS['phpgw']->template->set_var('messages',$GLOBALS['phpgw']->common->error_list($errors));
106                        $GLOBALS['phpgw']->template->pfp('out','form');
107                        $GLOBALS['phpgw']->common->phpgw_exit(True);
108                }
109                else
110                {
111                        $GLOBALS['phpgw_info']['user']['passwd'] = $GLOBALS['phpgw']->auth->change_password($o_passwd, $n_passwd);
112                        $GLOBALS['hook_values']['account_id'] = $GLOBALS['phpgw_info']['user']['account_id'];
113                        $GLOBALS['hook_values']['old_passwd'] = $o_passwd;
114                        $GLOBALS['hook_values']['new_passwd'] = $n_passwd;
115                        $GLOBALS['phpgw']->hooks->process('changepassword');
116                        $GLOBALS['phpgw']->redirect_link('/preferences/index.php','cd=18');
117                }
118        }
119        else
120        {
121                $GLOBALS['phpgw_info']['flags']['app_header'] = lang('Change your password');
122                $GLOBALS['phpgw']->common->phpgw_header();
123                echo parse_navbar();
124
125                $GLOBALS['phpgw']->template->pfp('out','form');
126                $GLOBALS['phpgw']->common->phpgw_footer();
127        }
128?>
Note: See TracBrowser for help on using the repository browser.