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

  • Home
  • SEARCH
  • 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 6213117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:38:21+00:00 2026-05-24T06:38:21+00:00

I have a User controller and User model. This model and associated database table

  • 0

I have a User controller and User model. This model and associated database table is used for authentication and naturally there’s a password field.

In my edit action when I call $this->data is puts the hashed password in my password field in my edit view. Naturally, I don’t want a password field with a 40-character value, which will then get re-hashed upon save.

My action looks like this:

function edit($id) {
    $this->User->id = $id;
    if (empty($this->data)) {
        $this->data = $this->User->read();
    }
    else {
        if ($this->User->save($this->data)) {
            $this->Session->setFlash('User has been updated.');
            $this->redirect(array('action' => 'view', $this->User->id));
        }
    }
}

And my view looks like this:

<h2>Edit User</h2>
<?php
    echo $this->Form->create('User', array('action' => 'edit'));
    echo $this->Form->input('username');
    echo $this->Form->input('password');
    echo $this->Form->input('first_name');
    echo $this->Form->input('last_name');
    echo $this->Form->input('email');
    echo $this->Form->end('Save User');
?>

How can I have a form for users to edit their account (username etc) that doesn’t update the password if left blank, but does update it if the user enters a new password into the password field?

  • 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-05-24T06:38:22+00:00Added an answer on May 24, 2026 at 6:38 am

    The common & most secure method is to have a separate form for changing the password where you ask the user to confirm the change by asking the old password. This is because if you forget the site open on a public computer, the next person who comes in can’t just hijack the account by just giving a new password.

    If you still want to go with the original plan, you can unset the variable if it’s empty before saving the data:

    if( $this->data[ 'User' ][ 'password' ] == '' ) {
        unset( $this->data[ 'User' ][ 'password' ] );
    }
    

    The other option is to list allowed fields as a parameter to save() and leave out password if the field is empty.

    In the view you can use

    echo $this->Form->input('password', array( 'value' => '' ) );
    

    to keep the hash from showing up in the field.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this model on mvc: public class User { public string Name {
I have a model called user and a controller for user with an action
I have a User class which may or may not have an associated Department.
I have a user model with a HABTM relationship to groups. I do not
I have a user model and a bid model. I want the user to
I have an application in CakePHP that lists businesses. I have a business model/controller,
This seemed easier in Web Forms; I'd have a user control, with the logic
Hi I have been trying to access the validation rules of an associated model
I have a controller/model called contacts and I have 2 other models that have
I am using the Zend Framework. I have a controller named 'UserController' that has

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.