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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:36:04+00:00 2026-06-08T13:36:04+00:00

By default, CakePHP seems to use the SHA1 algorithm to hash passwords and only

  • 0

By default, CakePHP seems to use the SHA1 algorithm to hash passwords and only seems to offer SHA256 as an alternative:

http://api.cakephp.org/view_source/security#line-86

I wanted to switch to a more secure password hashing solution before I make my application public to save future headaches when switching to a more secure hashing algorithm. I’ve looked around for some guides on using bcrypt or something similar but they all seem to be for older versions of Cake, or implement the hashing poorly.

Is there a guide somewhere that can show me how to integrate better password hashing without changing any code in my models or controllers?

Also, a little side question, why did the Cake devs only include SHA password hashing in their release? It’s common knowledge that SHA is a broken hashing algorithm for passwords, it just seems to me that such a reputable framework wouldn’t have overlooked this.

  • 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-08T13:36:06+00:00Added an answer on June 8, 2026 at 1:36 pm

    In this ticket CakePHP contributor Mark Story mentions that bcrypt will be supported in CakePHP 2.3 (yet to be released) and will become the standard/default in 3.0.

    Also, in this blog post Mark talks about what changes are needed to use bcrypt in CakePHP 2.0. Seems relatively minor, although will require changes to your user model.

    Borrowing the code from that post, what Mark did was created a subclass of FormAuthenticate:

    <?php
    App::uses('FormAuthenticate', 'Controller/Component/Auth');
    
    class BcryptFormAuthenticate extends FormAuthenticate {
    
    /**
     * The cost factor for the hashing.
     *
     * @var integer
     */
        public static $cost = 10;
    
    /**
     * Password method used for logging in.
     *
     * @param string $password Password.
     * @return string Hashed password.
     */
        protected function _password($password) {
            return self::hash($password);
        }
    
    /**
     * Create a blowfish / bcrypt hash.
     * Individual salts could/should used to be even more secure.
     *
     * @param string $password Password.
     * @return string Hashed password.
     */
        public static function hash($password) {
            $salt = substr(Configure::read('Security.salt'), 0, 22);
            return crypt($password, '$2a$' . self::$cost . '$' . $salt);
        }
    }
    

    Then made an update to the controller components array:

    <?php
    public $components = array(
        'Auth' => array(
            'authenticate' => 'BcryptForm',
            // other keys.
        )
    );
    

    And finally updating the User model’s beforeSave callback:

    <?php
    App::uses('BcryptFormAuthenticate', 'Controller/Component/Auth');
    
    class User extends AppModel {
        function beforeSave() {
            if (isset($this->data['User']['password'])) {
                $this->data['User']['password'] = BcryptFormAuthenticate::hash($this->data['User']['password']);
            }
            return true;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use cakePHP 2.0 and use the console tool to create one .../app/locale/default.pot .
We are struggling with a l10n problem in cakePHP. It seems that the default
i use cakephp and i am beginner i use $this->requestElement() in default.ctp file but
I cannot set title_for_layout in the PagesController that comes by default with CakePHP 1.3.
I am learning cakePHP, everything seems alright except that I am very confused of
How do I get rid of the default CakePHP: the rapid development php framework
I suffered a CakePHP Route Problem. I can only access the root / and
I need to redirect the default CakePHP home page / or (/pages/home) to /users/dashboard
By default, when I'm calling submit button in CakePHP View like this: echo $this->Form->end('Save');
FormHelper of CakePHP 2.0.6 ( in 1.3 works perfectly ), not accept app/Locale/pt_br/LC_MESSAGES/default.po. When

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.