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 7781357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:12:14+00:00 2026-06-01T19:12:14+00:00

I have a User Model, a UsersController and an AccountController which uses the User

  • 0

I have a User Model, a UsersController and an AccountController which uses the User Model (the account controller is used when an account is created, login, logout).

Everything works fine, except the beforeSave function in AccountController. I’m trying to use beforeSave to hash my password but it doesn’t work (the password is saved un-hashed in the database).

public function beforeSave() {
    parent::beforeSave();   

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

    return true;
}

A few notes:

  • I use “sha1” to hash the password because I’m converting an old system to CakePHP (the old system used sha1 to hash the passwords)
  • Even if I return false; the save function is still executed (which I thought should not be the case
  • calling debug($this->request->data) gives me nothing
  • I added the same beforeSave function in my UsersController but it didn’t work as well

I think in my case beforeSave is not being called, I just can’t figure out why.


Solved:
The beforeSave function has to go inside the model, this is my beforeSave function now:

public function beforeSave($options = array()) {
        parent::beforeSave();
        $this->data['User']['password'] = sha1($this->data['User']['password']);
        return true;
    }
  • 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-01T19:12:16+00:00Added an answer on June 1, 2026 at 7:12 pm

    beforeSave is a Model callback, so define it in your Model(s).

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

Sidebar

Related Questions

I have a user model on which I check to make sure that the
I have a User model and an Account model. The user has many accounts
I have a User model that has the following default_scope: default_scope where(account_id: Account.current_account.id) If
I have a plugin with user model, profile model and an user controller, in
I have a user model whose access controlled by ACL9. in UsersController : #ACL9
I have a User model (with all validators and properties defined) and a UsersController.
First of all I have a Model user.php which connects to users table. I
I have a User model with the usual information (login, email, name, location, etc).
I have a model called user and a controller for user with an action
I have a user model that requires the user to change their password every

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.