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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:33:29+00:00 2026-05-23T20:33:29+00:00

I’ve been using this tutorial to rewrite my login/logout functionality to handle authentication and

  • 0

I’ve been using this tutorial to rewrite my login/logout functionality to handle authentication and matching passwords in the model.

It now adds the user perfectly, but upon login the username/password fields are rejected. It seems the login function is looking for a differently hashed password than my new hashPasswords() function is storing. Any suggestions on what the problem could be?

It’s a fairly standard setup. Thanks for any help!

Pertinent Sections of code:

User Model:

var $validate = array(
    'password' => array(
        'The Password must be filled' =>array(            
            'rule' => 'notEmpty',
            'message' => 'Please supply a valid password.'
        ),
        'The Password must be between 5 and 15 characters' => array(
            'rule' => array('between', 5, 15),
            'message' => 'The password must be between 5 and 15 characters.'
        ),
        'The passwords do not match' => array(
            'rule' => 'matchPasswords',
            'message' => 'The passwords do not match.'
        )       
    ),

function hashPasswords($data) {
    if (isset($this->data['User']['password'])) {
        $this->data['User']['password'] = Security::hash($this->data['User']['password'], NULL, TRUE);
        return $data;
    }
    return $data;
}

function beforeSave() {
    $this->hashPasswords(NULL, TRUE);
    return TRUE;
}

Users Controller:

function beforeFilter() {
    parent::beforeFilter();
    if ($this->action == 'add' || $this->action == 'edit' ) {
        $this->Auth->authenticate = $this->User;
    }
}


function add() {
    if (!empty($this->data)) {

        if ($this->User->save($this->data)) {
                $this->Session->setFlash('Your Account Has Been Created.');
                $this->redirect(array('action' => 'homepage'));
        }
    }
}

function login() {

}   
  • 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-23T20:33:30+00:00Added an answer on May 23, 2026 at 8:33 pm

    I haven’t seen the video, but –

    When $this->data[‘User’] has a ‘username’ and ‘password’ array, and is used to save a user – cake actually hashes the password. What may potentially be happening is your hashed password being hashed again – check out the cake documentation on hashPassword

    As far as password matching goes – it is actually far easier to do this on the client side where they aren’t hashed (lots of Jquery functions out there that validate forms). You can even go as far as writing a simple:

    if($this->data['User']['password'] != $this->data['User']['password_conf']{
        $this->Session->setFlash('Passwords do not match');
    } else {
        //save user etc
    }
    

    If you want validate in the model, then certainly write a custom validation rule – but again the password will be hashed for you – you only need to compare the non-hashed versions and see if they match, returning true if they do.

    Also – everyone has completely different ways of authenticating users – first and foremost read the documentation – there’s an excellent tutorial for a simple Authenticated / ACL application which takes about 30 mins to go through and should be anyones starting point.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm looking for suggestions for debugging... If you view this site in Firefox or
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.