Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8306699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:22:58+00:00 2026-06-08T18:22:58+00:00

I have a CakePHP application with user registration. On the users page, I want

  • 0

I have a CakePHP application with user registration. On the users page, I want them to be able to update their email and password. THis is my User model:

<?php

class User extends AppModel {
    public $name = 'User';
    public $validate = array(
        'username' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'A username is required'
            ),
            'range' => array(
                'rule' => array('between', 4, 20),
                'message' => 'Between 4 and 20 characters'
            ),
            'characters' => array(
                'rule' => array('alphaNumeric'),
                'message' => 'Alphanumeric characters only'
            ),
            'unique' => array(
                'rule' => array('isUnique'),
                'message' => 'This username is taken'
            )
        ),
        'email' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'An email is required'
            ),
            'validEmail' => array(
                'rule' => array('email'),
                'message' => 'Please provide a valid email'
            ),
            'range' => array(
                'rule' => array('between', 5, 64),
                'message' => 'Between 5 and 64 characters'
            ),
            'unique' => array(
                'rule' => array('isUnique'),
                'message' => 'This email has already been used'
            )
        ),
        'password' => array(
            'required' => array(
                'rule' => array('notEmpty'),
                'message' => 'A password is required'
            ),
            'range' => array(
                'rule' => array('between', 5, 64),
                'message' => 'Between 5 and 64 characters'
            ),
        )
    );

    public function beforeSave() {
        if (isset($this->data[$this->alias]['password'])) {
            $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
        }
        return true;
    }

}

And I’m using the form helper to create the form:

<p>Modify your account settings</p>
<?php echo $this->Session->flash(); ?>
<?php
    echo $this->Form->create('User');
    echo $this->Form->input('currentPassword', array('type' => 'password'));
    echo $this->Form->input('username', array('disabled' => 'disabled', 'value' => $username));
    echo $this->Form->input('email');
    echo $this->Form->input('newPassword', array('type' => 'password'));
    echo $this->Form->end('Update');
?>

How would I go about checking if the current password is valid, checking if the new email and password pass validation rules and then updating the users record in my users table from within my controller?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:22:59+00:00Added an answer on June 8, 2026 at 6:22 pm

    Adding a new user – UsersController.php:

    public function add() {
            if ($this->request->is('post')) {
                $this->User->create();
                        if ($this->User->save($this->request->data)) {
                    $this->Session->setFlash(__('Registration complete. :)'));
                    $this->redirect(array('action' => 'index'));
                } else {
                    $this->Session->setFlash(__('Error... Please try again.'));
                }
            }
        }
    

    Editing a user – UsersController.php:

    public function edit($id = null) {
        $this->User->id = $id;
        if (!$this->User->exists()) {
            throw new NotFoundException(__('Invalid user'));
        }
        if ($this->request->is('post') || $this->request->is('put')) {
            if($this->Auth->user('password') == AuthComponent::password($this->request->data['User']['password']){
            if ($this->User->save($this->request->data)) {
                $this->Session->setFlash(__('The user has been saved'));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The user could not be saved. Please, try again.'));
            }
        }}else{
             $this->Session->setFlash(__('Incorrect password.'));
            }
             else {
            $this->request->data = $this->User->read(null, $id);
        }
    }
    

    Just watch for {}. 😀

    If it doesn’t work, try

    if($this->Auth->user('password') == $this->request->data['User']['password'])...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CakePHP Application which I want to protect with a password. The
I have an application I am developing where the user is allowed to email
let's say i have: http://some-domain/application/controller/action/parameter This is somehow working in cakePHP. Now I want
Background I have a CakePHP application that lives in /m/ . I want to
I have a cakePHP application with an advanded search section. When a user applys
In my CakePHP application, I have a model like this: class Duck extends AppModel
I have an existing PHP/MySQL application that I want to convert over to CakePHP.
I have 2 basic models in my CakePHP application: User and Login. A user
I'm building a CakePHP application and I have an API controller. This holds some
I have a CakePHP application that allows a user to register and post projects.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.