source: trunk/preferences/changepassword.php @ 72

Revision 72, 6.8 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                if(($GLOBALS['phpgw_info']['user']['lastpasswd_change'] == '0') && (!$_POST['cancel']))
29                        $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/login.php','cd=6'));
30               
31                if ($GLOBALS['phpgw_info']['server']['use_https'] == 1)
32                        Header('Location: http://' . $_SERVER['HTTP_HOST'] . $GLOBALS['phpgw_info']['server']['webserver_url'] . '/preferences/index.php');
33                else
34                        $GLOBALS['phpgw']->redirect_link('/preferences/index.php');
35               
36                $GLOBALS['phpgw']->common->phpgw_exit();
37        }
38
39        $GLOBALS['phpgw']->template->set_file(array(
40                'form' => 'changepassword.tpl'
41        ));
42        $GLOBALS['phpgw']->template->set_var('lang_enter_actual_password',lang('Enter your actual password'));
43        $GLOBALS['phpgw']->template->set_var('lang_enter_password',lang('Enter your new password'));
44        $GLOBALS['phpgw']->template->set_var('lang_reenter_password',lang('Re-enter your password'));
45        $GLOBALS['phpgw']->template->set_var('lang_change',lang('Change'));
46        $GLOBALS['phpgw']->template->set_var('lang_cancel',lang('Cancel'));
47        $GLOBALS['phpgw']->template->set_var('form_action',$GLOBALS['phpgw']->link('/preferences/changepassword.php'));
48
49        if ($_GET['cd'] == 1)
50        {
51                $lang1 = lang('Your password has expired');
52                $lang2 = lang('You must register a new password');
53                $GLOBALS['phpgw']->template->set_var('messages',"<font color=red><h1>$lang1.<br>$lang2.</h1></font>");
54        }
55
56        if ($GLOBALS['phpgw_info']['server']['auth_type'] != 'ldap')
57        {
58                $GLOBALS['phpgw']->template->set_var('sql_message',lang('note: This feature does *not* change your email password. This will '
59                        . 'need to be done manually.'));
60        }
61
62        if ($_POST['change'])
63        {
64                // Default number of letters = 3
65                if (!$GLOBALS['phpgw_info']['server']['num_letters_userpass'])
66                        $GLOBALS['phpgw_info']['server']['num_letters_userpass'] = 3;
67                // Default number of special letters = 0
68                if (!$GLOBALS['phpgw_info']['server']['num_special_letters_userpass'])
69                        $GLOBALS['phpgw_info']['server']['num_special_letters_userpass'] = 0;
70                if (! $GLOBALS['phpgw']->auth->authenticate($GLOBALS['phpgw_info']['user']['account_lid'], $a_passwd))
71                {
72                        $errors[] = lang('Your actual password is wrong');
73                }
74                else if ($n_passwd != $n_passwd_2)
75                {
76                        $errors[] = lang('The two passwords are not the same');
77                }
78                else if ($a_passwd == $n_passwd)
79                {
80                        $errors[] = lang('Your old password and your new password are the same. Choose a different new password');
81                }
82                else if (! $n_passwd)
83                {
84                        $errors[] = lang('You must enter a password');
85                }
86                else if ( strlen( $n_passwd ) < $GLOBALS['phpgw_info']['server']['num_letters_userpass'] )
87                {
88                        $errors[] = lang('Your password must contain %1 or more letters', $GLOBALS['phpgw_info']['server']['num_letters_userpass']);                   
89                }               
90                # password that start with a-Z or 0-9 and contain _.-!@#$%&*+=| will be accepted.
91                //else if (! ereg ("(^[a-zA-Z0-9_.\-\!@#$%&*+=|]*)$", $n_passwd ) )
92                //else if (! ereg ("(^[a-zA-Z0-9_.\-\!@#$%&*+=|\(\)\^\~\}\{\[\]\/\\\"\'\:\;\?]*)$", $n_passwd ) )
93                else if (! ereg ("([]^[a-zA-Z0-9\_\.\-\!\@\#\$\%\&\*\+\=\|\(\)\^\~\}\{\/\\\"\'\:\;\?]*)$", $n_passwd ) )
94                {                       
95                        $errors[] = lang('Your password contains characters not allowed');
96                }               
97                # password must contain 2 special letters, numbers or special characters
98                //else if ($GLOBALS['phpgw_info']['server']['num_special_letters_userpass'] && ! ereg ("([0-9_.\-!@#$%&*+=|]){".$GLOBALS['phpgw_info']['server']['num_special_letters_userpass'].",}", $n_passwd ) )
99                //else if ($GLOBALS['phpgw_info']['server']['num_special_letters_userpass'] && ! ereg ("([0-9_.\-!@#$%&*+=|\(\)\^\~\}\{\[\]\/\\\"\'\:\;\?]){".$GLOBALS['phpgw_info']['server']['num_special_letters_userpass']."}", $n_passwd ) )
100                else if ($GLOBALS['phpgw_info']['server']['num_special_letters_userpass'] && ! ereg ("([][0-9\_\.\-\!\@\#\$\%\&\*\+\=\|\(\)\^\~\}\{\/\\\"\'\:\;\?]){".$GLOBALS['phpgw_info']['server']['num_special_letters_userpass']."}", $n_passwd ) )
101                {
102                        $errors[] = lang('Your password must contain at least %1 numbers or characters special', $GLOBALS['phpgw_info']['server']['num_special_letters_userpass']);
103                }
104               
105                if(is_array($errors))
106                {
107                        $GLOBALS['phpgw']->common->phpgw_header();
108                        echo parse_navbar();
109                        $GLOBALS['phpgw']->template->set_var('messages',$GLOBALS['phpgw']->common->error_list($errors));
110                        $GLOBALS['phpgw']->template->pfp('out','form');
111                        $GLOBALS['phpgw']->common->phpgw_exit(True);
112                }
113
114                $o_passwd = $GLOBALS['phpgw_info']['user']['passwd'];
115                $passwd_changed = $GLOBALS['phpgw']->auth->change_password($o_passwd, $n_passwd);
116                if(!$passwd_changed)
117                {
118                        $errors[] = lang('Failed to change password.  Please contact your administrator.');
119                        $GLOBALS['phpgw']->common->phpgw_header();
120                        echo parse_navbar();
121                        $GLOBALS['phpgw']->template->set_var('messages',$GLOBALS['phpgw']->common->error_list($errors));
122                        $GLOBALS['phpgw']->template->pfp('out','form');
123                        $GLOBALS['phpgw']->common->phpgw_exit(True);
124                }
125                else
126                {
127                        $GLOBALS['phpgw_info']['user']['passwd'] = $GLOBALS['phpgw']->auth->change_password($o_passwd, $n_passwd);
128                        $GLOBALS['hook_values']['account_id'] = $GLOBALS['phpgw_info']['user']['account_id'];
129                        $GLOBALS['hook_values']['old_passwd'] = $o_passwd;
130                        $GLOBALS['hook_values']['new_passwd'] = $n_passwd;
131                        $GLOBALS['phpgw']->hooks->process('changepassword');
132                       
133                        if ($GLOBALS['phpgw_info']['server']['use_https'] == 1)
134                                Header('Location: http://' . $_SERVER['HTTP_HOST'] . $GLOBALS['phpgw_info']['server']['webserver_url'] . '/preferences/index.php');
135                        else
136                                $GLOBALS['phpgw']->redirect_link('/preferences/index.php','cd=18');
137                }
138        }
139        else
140        {
141                $GLOBALS['phpgw_info']['flags']['app_header'] = lang('Change your password');
142                $GLOBALS['phpgw']->common->phpgw_header();
143                echo parse_navbar();
144
145                $GLOBALS['phpgw']->template->pfp('out','form');
146                $GLOBALS['phpgw']->common->phpgw_footer();
147        }
148?>
Note: See TracBrowser for help on using the repository browser.