I’m not really sure what’s going on here. This is what I have in my app_controller.php:
<?php
class AppController extends Controller {
var $components = array('Auth');
var $helpers = array('Form', 'Session');
function beforeFilter() {
$this->Auth->allow('register');
$this->Auth->userScope = array('User.activated' => true);
$this->Auth->loginError = "<span style=\"color:#FF0000\">Wrong username or password</span>";
$this->Auth->fields = array(
'username' => 'username',
'password' => 'password'
);
}
}
?>
and my users_controller.php:
<?php
class UsersController extends AppController {
var $name = 'Users';
var $components = array('Auth');
var $helpers = array('Form', 'Session');
function index() {
}
function login() {
$this->set('title_for_layout', "Welcome to .com!");
$this->layout = 'user_functions';
}
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 = //email
$to = $this->data['User']['e-mail'];
$subject = 'Welcome to .com!';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: '';
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
}
}
}
}
?>
and here’s my 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->data); echo "</pre>";
?>
</div>
Basically, when I try to login using my login form, even if I use the password that I used when I registered, it says that the username or password is incorrect. However, when I changed the password stored in the database to ‘password’ in plain text, and tried logging in with that, it worked! I have no idea why this is happening. I also echoed out $this->data on the login view, and the username is right, but the password is empty. From what I can see , the password is just not hashing.
EDIT
I think you mean mask, not hash, the password at input time. This should be simple…