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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:50:11+00:00 2026-06-07T23:50:11+00:00

My goal is to have a unique salt for each user rather than just

  • 0

My goal is to have a unique salt for each user rather than just using Configure::read('Security.salt') for every user.

I know that CakePHP 2.x no longer hashes passwords automatically. This allows me to perform model validation on passwords, which is very nice. However, I don’t see a way that I can override the AuthComponent’s “password” method. So even though I can control how passwords are hashed before they are saved to the database, I cannot control how passwords are hashed when performing the actual login. From the cookbook:

You don’t need to hash passwords before calling
$this->Auth->login().

What can I do to make $this->Auth->login() use a custom method of password hashing?

Thanks.

UPDATE: I ended up going with dr Hannibal Lecter’s answer (creating a custom authentication object). Here’s how to do it:

Old code:

$this->Auth->authenticate = array('Form' => array('fields' => array('username' => 'email')));

New code (change “Form” to “Custom”):

$this->Auth->authenticate = array('Custom' => array('fields' => array('username' => 'email')));

Create “app/Controller/Component/Auth/CustomAuthenticate.php” and make it look like this:

<?php
App::uses('FormAuthenticate', 'Controller/Component/Auth');

class CustomAuthenticate extends FormAuthenticate {
}

Copy the “_findUser” and “_password” methods from “lib/Cake/Controller/Component/Auth/BaseAuthenticate.php” and paste them into the “CustomAuthenticate” class. Then make the following two modifications to the “_findUser” method:

  1. Remove this line from the “$conditions” array: $model . '.' . $fields['password'] => $this->_password($password),

  2. Change if (empty($result) || empty($result[$model])) { to if (empty($result) || empty($result[$model]) || $result[$model][$fields['password']] != $this->_password($password, $result[$model]['id'])) {

Then make the following two modifications to the “_password” method:

  1. Create the “$id” parameter by changing protected function _password($password) { to protected function _password($password, $id) {

  2. Update the salt value by changing return Security::hash($password, null, true); to return Security::hash($password, null, Configure::read('Security.salt') . $id);

Lastly, update all occurrences of AuthComponent::password to use Security::hash with the same logic as above.

  • 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-07T23:50:13+00:00Added an answer on June 7, 2026 at 11:50 pm

    You could probably create a custom auth object and hash the password however you like. Take a look at the existing auth objects to get the general idea of how they work.

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

Sidebar

Related Questions

My goal is to have a jQuery datepicker pop up when the user clicks
My goal is to have a user select a year and a month. Translate
So, I have a particularly unique goal I wish to achieve with CSS, HTML
I have a rather unique problem that I'm having trouble solving. I have a
Please read the entire question. I have a unique situation with several constraints that
Goal: Get values which are unique in $resultSecond So I have two objects. $result
I have a unique SMS problem: The end goal is to replace the phone
I'm using acts_as_taggable_on, but now have a new requirement: The end goal: Users should
Final goal: Have a few java objects sharing the same base class persisted into
goal: I have the string 1234432144 I want to only replace the first 2

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.