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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:19:11+00:00 2026-05-28T07:19:11+00:00

Ok, so I was having a very interesting issue with CakePHP 1.3, in that

  • 0

Ok, so I was having a very interesting issue with CakePHP 1.3, in that even if I used the correct information to try to log in, it wouldn’t work. I’ve now upgraded the same app to Cakephp 2.0, and I’m having a very different issue. Basically now, regardless of what information I put in when I’m logging in, it will log in. Even if the database is empty. No idea why this is happening…

Here’s my code:

View:

<div id="login">
<p>Please log in! <a id="register" href="register" alt="Register">Register</a></p>
<hr class="login"/>
<?php    
    echo $this->Session->flash('auth');    
    echo $this->Form->create('User');    
    echo $this->Form->input('username');
    echo $this->Form->input('password');
    echo "<hr class=\"login\"/>";
    echo $this->Form->end('Login');
    echo $this->Session->flash('flash_registration');
    echo "<pre>"; print_r($this->request->data); echo "</pre>";
    echo $this->Html->link('Log-Out', 'logout');
?>

</div>

Model:

<?php
App::uses('AuthComponent', 'Controller/Component');
class User extends AppModel {
var $name = 'User';
var $validate = array(
    'name' => array(
        'custom_rule' => array(
            'rule' => '/^[A-Za-z\s]*$/i',
            'message' => 'Please enter an acceptable name'
            ),
        'notEmpty' => array(
            'rule' => array('notEmpty'),
            'message' => 'This field is required'
        )
    ),
    'dob' => array(
        'rule' => array('date', 'ymd'),
        'message' => 'Enter a valid date',
    ),
    'phone' => array(
        'numbers' => array(
            'rule' => 'numeric',
            'message' => 'Numbers only, no dashes or spaces'
        ),
        'notEmpty' => array(
            'rule' => array('notEmpty'),
            'message' => 'This field is required'
        )
    ),
    'username' => array(
        'alphaNumeric' => array(
            'rule' => 'alphaNumeric',
            'message' => 'Letters and numbers only'
        ),
        'notEmpty' => array(
            'rule' => array('notEmpty'),
            'message' => 'This field is required'
        )
    ),
    'e-mail' => array(
        'email' => array(
            'rule' => 'email',
            'message' => 'Please enter a valid e-mail address'
        ),
        'notEmpty' => array(
            'rule' => array('notEmpty'),
            'message' => 'This field is required'
        )
    ),
    'password_enter' => array(
        'length' => array(
            'rule' => array('between', 8, 16),
            'message' => 'Password must be between 8 and 16 characters'
        ),
        'notEmpty' => array(
            'rule' => array('notEmpty'),
            'message' => 'This field is required'
        )
    ),
    'password_confirm' => array( 
        'identicalFieldValues' => array( 
            'rule' => array('identicalFieldValues', 'password_enter'), 
            'message' => 'Passwords do not match'
        ),
        'length' => array(
            'rule' => array('between', 8, 16),
            'message' => 'Password must be between 8 and 16 characters'
        ),
        'notEmpty' => array(
            'rule' => array('notEmpty'),
            'message' => 'This field is required'
        )
    )
);

function identicalFieldValues( $field=array(), $compare_field=null ){
    foreach( $field as $key => $value ){ 
        $v1 = $value; 
        $v2 = $this->data[$this->name][ $compare_field ];
        if($v1 !== $v2) { 
            return FALSE; 
        } else { 
            return TRUE;
        }
    } 
}
function beforeValidate(){ 

    $this->data['User']['dob'] = $this->data['User']['dob'];

    return true;
}
function beforeSave(){

    $this->data['User']['password'] = AuthComponent::password($this->data['User']['password_enter']);
    $this->data['User']['activated'] = FALSE;

    return TRUE;
}

}

?>

Controller:

<?php

class UsersController extends AppController {

var $name = 'Users';
var $uses = array("User");
var $components = array(
        'Session',
        'Auth' => array(
            'loginRedirect' => array('controller' => 'pages', 'action' => 'index'),
            'logoutRedirect' => array('controller' => 'users', 'action' => 'login')
        )
    );

var $helpers = array('Form', 'Session', 'Html');

function beforeFilter(){
    // Basic setup
    $this->Auth->authenticate = array('Form');
    $this->Auth->allow('register', 'activate');

}

function index() {



}

function login() {
    $this->Auth->login($this->request->data);
    $this->set('title_for_layout', "Welcome to Sound-On.com!");
    $this->layout = 'user_functions';
    if ($this->Auth->user()) {
        echo "Logged in!";
    } else {
        echo "Not logged in!";
    }
}

function logout() {

    $this->redirect($this->Auth->logout());

}

function register(){

    $this->set('title_for_layout', "Register Here!");
    $this->layout = 'user_functions';
    $date = date('Y');

    if (!empty($this->data)) {
        $user_check = $this->User->find('first', array('conditions' => array('username' => $this->data['User']['username'])));
        $email_check = $this->User->find('first', array('conditions' => array('e-mail' => $this->data['User']['e-mail'])));
        if (empty($user_check)) {
            if(empty($email_check)){
                if ($this->User->save($this->data)) {
                    $uuid_string = $this->data['User']['activation_hash'];
                    $email = <<<EOT
                    <html>
                        <head>
                            <title>Welcome to Sound-On.com!</title>
                        </head>
                        <body>
                            <p>
                                <h1>Welcome to Sound-on.com!</h1>

                                <p>You have successfully registered! To activate your account and start sounding on, please click <a href="http://www.sound-on.com/activate?uid=$uuid_string">Here</a>! <br/>If the link is not clickable, please copy and paste the link below into your browser address bar.</p>

                                http://www.sound-on.com/activate?uid=$uuid_string

                                <p style="">Thank you for registering!</p>
                                                <p>Your friendly Sound-On registration robot</p>

                                <p>If you did not register or wish to remove your account, please click <a href="http://www.sound-on.com/not-me?uid=$uuid_string">here</a>.</p>

                                <p style="font-size:8pt;color:#707070">&copy; Copyright $date Sound-on.com. All rights Reserved.</p>
                            </p>
                        </body
                    </html>
EOT;
                    $to = $this->data['User']['e-mail'];
                    $subject = 'Welcome to Sound-On.com!';
                    $headers = "MIME-Version: 1.0" . "\r\n";
                    $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
                    $headers .= 'From: registration@Sound-On.com';

                    if (mail($to, $subject, $email, $headers)) {
                        $this->redirect('/');
                    }
                } else {
                    //$this->Session->setFlash('<p class="register_flash">Something went wrong. Please try again.</p>', 'flash_registration');
                    //$this->flash('', '/');
                }
            } else {

                //email exists

            }
        } else {

            //username exists

        }
    }   
}

function activate(){

    $this->set('title_for_layout', "Register Here!");
    $this->layout = 'user_functions';
    if (!empty($_GET)) {
        $activate = $this->User->updateAll(array('activated' => 1), array('activation_hash' => $_GET['uuid']));
        if ($activate) {
            $this->set('message', '<p id="activation_message">Your account has been successfully activated! Please click <a href="/">here</a> to proceed to login!</p>');
        }
    }

}
}





?>

Thanks in advance!

  • 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-28T07:19:12+00:00Added an answer on May 28, 2026 at 7:19 am

    If you send data to the Auth->login() function it will log in with the data.

    http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#identifying-users-and-logging-them-in

    You need to use something like this.

    public function login() {
        if ($this->request->is('post')) {
            if (!$this->Auth->login()) {
                $this->Session->setFlash('Your username or password was incorrect.');
            } else {
                $this->Session->setFlash('You are now logged in.');
                //redirect
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having an interesting issue with Leptonica that I'm wondering if other SO members
Im having a very strange problem, i have a complicated view that returns incorrect
I'm having a very strange issue with Python's subprocess.Popen. I'm using it to call
I've been having a very hard time finding good examples of UIScrollView. Even Apple's
I am having a very interesting problem. The script I wrote below works, but
I'm having a very odd issue where I am trying to use a text
CakePHP has an annoying habit of having very deep, multidimensional arrays when pulling data
I'm having a very odd problem that I can't seem to track down. Any
I have found out that C++ standard functions show very different behavior when having
Very simple question that I've been having trouble answering. In Windows XP and Server

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.