我不确定这里发生了什么。这就是我在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'
);
}
}
?>
和我的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
}
}
}
}
?>
这是我的观点:
<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>
基本上,当我尝试使用我的登录表单登录时,即使我使用我在注册时使用的密码,也会说用户名或密码不正确。但是,当我将存储在数据库中的密码更改为纯文本中的“密码”,并尝试使用该密码登录时,它工作正常!我不知道为什么会这样。我还在登录视图上回显了$ this-&gt;数据,用户名是正确的,但密码为空。从我所看到的,密码不是散列。
答案 0 :(得分:0)
我认为你的意思是掩码,而不是哈希,输入时的密码。这应该很简单......
echo $this->Form->input('password', array('type' => 'password'));