application/modules/g/controllers/AuthController.php
public function resetpasswordAction() {
        $this->view->title = __('reset password page title');
        $authVars = Garp_Auth::getInstance()->getConfigValues();
        $activationCode = $this->getRequest()->getParam('c');
        $activationEmail = $this->getRequest()->getParam('e');
        $expirationColumn = $authVars['forgotpassword']['activation_code_expiration_date_column'];

        $userModel = new Model_User();
        $activationCodeClause = 'MD5(CONCAT(' .
                $userModel->getAdapter()->quoteIdentifier(
                    $authVars['forgotpassword']['activation_token_column']
                ) . ',' .
                'MD5(email),' .
                'MD5(' . $userModel->getAdapter()->quote($authVars['salt']) . '),' .
                'MD5(id)' .
            ')) = ?'
        ;
        $select = $userModel->select()
            // check if a user matches up to the given code
            ->where($activationCodeClause, $activationCode)
            // check if the given email address is part of the same user record
            ->where('MD5(email) = ?', $activationEmail);

        $user = $userModel->fetchRow($select);
        if (!$user) {
            $this->view->error = __('reset password user not found');
            return;
        }
        if (strtotime($user->{$expirationColumn}) < time()) {
            $this->view->error = __('reset password link expired');
            return;
        }
        if (!$this->getRequest()->isPost()) {
            return;
        }
        $password = $this->getRequest()->getPost('password');
        if (!$password) {
            $this->view->formError = sprintf(__('%s is a required field'), ucfirst(__('password')));
            return;
        }

        if (!empty($authVars['forgotpassword']['repeatPassword'])
            && !empty($authVars['forgotpassword']['repeatPasswordField'])
        ) {
            $repeatPasswordField = $this->getRequest()->getPost(
                $authVars['forgotpassword']['repeatPasswordField']
            );
            if ($password != $repeatPasswordField) {
                $this->view->formError = __('the passwords do not match');
                return;
            }
        }

        // Update the user's password and send him along to the login page
        $updateClause = $userModel->getAdapter()->quoteInto('id = ?', $user->id);
        $userModel->update(
            array(
            'password' => $password,
            $authVars['forgotpassword']['activation_token_column'] => null,
            $authVars['forgotpassword']['activation_code_expiration_date_column'] => null
            ), $updateClause
        );
        $this->_helper->flashMessenger(__($authVars['resetpassword']['success_message']));
        $this->_redirect('/g/auth/login');
    }
public function resetpasswordAction() {
        $this->view->title = __('reset password page title');
        $authVars = Garp_Auth::getInstance()->getConfigValues();
        $activationCode = $this->getRequest()->getParam('c');
        $activationEmail = $this->getRequest()->getParam('e');
        $expirationColumn = $authVars['forgotpassword']['activation_code_expiration_date_column'];

        $userModel = new Model_User();
        $activationCodeClause = 'MD5(CONCAT(' .
                $userModel->getAdapter()->quoteIdentifier(
                    $authVars['forgotpassword']['activation_token_column']
                ) . ',' .
                'MD5(email),' .
                'MD5(' . $userModel->getAdapter()->quote($authVars['salt']) . '),' .
                'MD5(id)' .
            ')) = ?'
        ;
        $select = $userModel->select()
            // check if a user matches up to the given code
            ->where($activationCodeClause, $activationCode)
            // check if the given email address is part of the same user record
            ->where('MD5(email) = ?', $activationEmail);

        $user = $userModel->fetchRow($select);
        if (!$user) {
            $this->view->error = __('reset password user not found');
            return;
        }
        if (strtotime($user->{$expirationColumn}) < time()) {
            $this->view->error = __('reset password link expired');
            return;
        }
        if (!$this->getRequest()->isPost()) {
            return;
        }
        $password = $this->getRequest()->getPost('password');
        if (!$password) {
            $this->view->formError = sprintf(__('%s is a required field'), ucfirst(__('password')));
            return;
        }

        if (!empty($authVars['forgotpassword']['repeatPassword'])
            && !empty($authVars['forgotpassword']['repeatPasswordField'])
        ) {
            $repeatPasswordField = $this->getRequest()->getPost(
                $authVars['forgotpassword']['repeatPasswordField']
            );
            if ($password != $repeatPasswordField) {
                $this->view->formError = __('the passwords do not match');
                return;
            }
        }

        // Update the user's password and send him along to the login page
        $updateClause = $userModel->getAdapter()->quoteInto('id = ?', $user->id);
        $userModel->update(
            array(
            'password' => $password,
            $authVars['forgotpassword']['activation_token_column'] => null,
            $authVars['forgotpassword']['activation_code_expiration_date_column'] => null
            ), $updateClause
        );
        $this->_helper->flashMessenger(__($authVars['resetpassword']['success_message']));
        $this->_redirect('/g/auth/login');
    }
public function resetpasswordAction ( ) { $ this -> view -> title = __ ( 'reset password page title' ) ; $ authVars = Garp_Auth :: getInstance ( ) -> getConfigValues ( ) ; $ activationCode = $ this -> getRequest ( ) -> getParam ( 'c' ) ; $ activationEmail = $ this -> getRequest ( ) -> getParam ( 'e' ) ; $ expirationColumn = $ authVars [ 'forgotpassword' ] [ 'activation_code_expiration_date_column' ] ; $ userModel = new Model_User ( ) ; $ activationCodeClause = 'MD5(CONCAT(' . $ userModel -> getAdapter ( ) -> quoteIdentifier ( $ authVars [ 'forgotpassword' ] [ 'activation_token_column' ] ) . ',' . 'MD5(email),' . 'MD5(' . $ userModel -> getAdapter ( ) -> quote ( $ authVars [ 'salt' ] ) . '),' . 'MD5(id)' . ')) = ?' ; $ select = $ userModel -> select ( ) // check if a user matches up to the given code -> where ( $ activationCodeClause , $ activationCode ) // check if the given email address is part of the same user record -> where ( 'MD5(email) = ?' , $ activationEmail ) ; $ user = $ userModel -> fetchRow ( $ select ) ; if ( ! $ user ) { $ this -> view -> error = __ ( 'reset password user not found' ) ; return ; } if ( strtotime ( $ user -> { $ expirationColumn } ) < time ( ) ) { $ this -> view -> error = __ ( 'reset password link expired' ) ; return ; } if ( ! $ this -> getRequest ( ) -> isPost ( ) ) { return ; } $ password = $ this -> getRequest ( ) -> getPost ( 'password' ) ; if ( ! $ password ) { $ this -> view -> formError = sprintf ( __ ( '%s is a required field' ) , ucfirst ( __ ( 'password' ) ) ) ; return ; } if ( ! empty ( $ authVars [ 'forgotpassword' ] [ 'repeatPassword' ] ) && ! empty ( $ authVars [ 'forgotpassword' ] [ 'repeatPasswordField' ] ) ) { $ repeatPasswordField = $ this -> getRequest ( ) -> getPost ( $ authVars [ 'forgotpassword' ] [ 'repeatPasswordField' ] ) ; if ( $ password != $ repeatPasswordField ) { $ this -> view -> formError = __ ( 'the passwords do not match' ) ; return ; } } // Update the user's password and send him along to the login page $ updateClause = $ userModel -> getAdapter ( ) -> quoteInto ( 'id = ?' , $ user -> id ) ; $ userModel -> update ( array ( 'password' => $ password , $ authVars [ 'forgotpassword' ] [ 'activation_token_column' ] => null , $ authVars [ 'forgotpassword' ] [ 'activation_code_expiration_date_column' ] => null ) , $ updateClause ) ; $ this -> _helper -> flashMessenger ( __ ( $ authVars [ 'resetpassword' ] [ 'success_message' ] ) ) ; $ this -> _redirect ( '/g/auth/login' ) ; }
Allow a user to reset his password after he had forgotten it.

@return void
Allow a user to reset his password after he had forgotten it .