source: trunk/services/password.php @ 312

Last change on this file since 312 was 202, checked in by scdev, 18 years ago

Q - updated usage of $nav.

File size: 2.8 KB
RevLine 
[1]1<?php
2/**
[42]3 * password.php
[1]4 * Code by Strangecode :: www.strangecode.com :: This document contains copyrighted information
5 */
6
7// require_once dirname(__FILE__) . '/_config.inc.php';
8
9$auth->requireLogin();
10
11require_once 'codebase/lib/FormValidator.inc.php';
12
13/******************************************************************************
14 * CODE CONFIG
15 *****************************************************************************/
[42]16
[1]17// Titles and navigation header.
[202]18$nav->add(_("Change password"));
[1]19
20// The object to validate form input from the user.
21$fv = new FormValidator();
22
[143]23/********************************************************************
24* MAIN
25********************************************************************/
[1]26
[20]27if (getFormData('boomerang', false) && isset($_SERVER['HTTP_REFERER'])) {
[1]28    // We remember which page we came from so we can go back there.
[136]29    $app->setBoomerangURL($_SERVER['HTTP_REFERER'], 'admin_password');
[1]30}
[136]31$app->sslOn();
[1]32
33switch (getFormData('op')) {
34case 'update_password' :
35
36    // Get the form variables.
37    $frm = getFormData();
38
39    // Validate the posted data.
40//  $fv->isEmpty('oldpassword', _("You did not specify the <strong>old password</strong>."));
41    $fv->checkRegex('oldpassword', '/^[[:alnum:][:punct:]]{0,128}$/i', true, _("The <strong>Old password</strong> specified is not valid."));
42    if (!$fv->isEmpty('newpassword', _("You did not specify the <strong>New password</strong>."))) {
43        $fv->checkRegex('newpassword', '/^[[:alnum:][:punct:]]{6,128}$/i', true, _("The <strong>New password</strong> specified is not valid. A password must be 6 or more characters."));
44        if ($frm['newpassword'] != $frm['newpassword2'] && !$fv->isEmpty('newpassword2', _("You need to type the <strong>New password</strong> twice."))) {
45            $fv->addError('newpassword', _("The <strong>New passwords</strong> do not match."));
46            $fv->addError('newpassword2');
47        }
48    }
[42]49
[147]50    if (!$fv->anyErrors() && false === $auth->authenticate($auth->get('username'), $frm['oldpassword'])) {
[1]51        $fv->addError('oldpassword', _("Your <strong>Old password</strong> failed authentication."));
[147]52        $app->logMsg(sprintf('Password change failed for %s, using (md5ed) password: %s', $auth->get('username'), md5($frm['oldpassword'])), LOG_NOTICE, __FILE__, __LINE__);
[1]53    }
54
55    if (!$fv->anyErrors()) {
56        $auth->setPassword(null, $frm['newpassword']);
[147]57        $app->logMsg(sprintf('Password change successful for %s', $auth->get('username')), LOG_INFO, __FILE__, __LINE__);
58        $app->raiseMsg(sprintf(_("Password change successful for %s"), $auth->get('username')), MSG_SUCCESS, __FILE__, __LINE__);
[136]59        $app->dieBoomerangURL('admin_password');
[1]60    }
61    break;
62}
63
64// Templates.
65include 'header.ihtml';
[20]66include 'codebase/services/templates/password.ihtml';
[1]67include 'footer.ihtml';
68
69?>
Note: See TracBrowser for help on using the repository browser.