0
我想寫一個基本用戶註冊頁面,我的問題是檢查password
長度字符串。我已經讀過各種問題和解決方案,但我仍然陷入困境。在CakePHP中檢查註冊的密碼長度問題
這是我寫的:
class UsersController extends AppController {
function register() {
if (!empty ($this->data)) {
if ($this->data['User']['password'] == $this->Auth->password($this->data['User']['password_confirm'])) {
if ($this->User->save($this->data)) {
$this->Session->setFlash('All ok');
$this->redirect(array('action', 'login'));
}
} else {
$this->Session->setFlash('Password mismatch');
$this->redirect(array('action', 'register'));
}
}
}
}
然後用戶模式:
var $validate = array (
'username' => array (
'alphaNumeric' => array(
'rule' => 'alphaNumeric',
'required' => true,
'message' => 'Alphanumeric chars only'
),
'between' => array(
'rule' => array('between', 1, 24),
'message' => 'Username between 1 and 24 chars'
)
),
'password' => array (
'between' => array(
'rule' => array('between', 7, 25),
'message' => 'Password between 8 and 24 chars'
)
)
);
文件register.ctp
<?php
echo $this->Form->create('User');
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->input('password_confirm', array('type' => 'password'));
echo $this->Form->end('Register account');
?>
密碼和password_confirm檢查完美的作品,如果我寫不同的密碼我得到的錯誤,如果密碼相同,我得到一個密碼ord長度錯誤,我錯了?
日誌:
2011-03-29 23:20:41 Error: Array
(
[User] => Array
(
[username] => tonino
[password] => ae4f47749b697085b2f7322383fa7b14c79e06f6
[password_confirm] => passwordtest
)
)
我忘了說我的密碼是SHA1 hashed
,所以我怎麼能檢查是否有用戶寫太長的密碼?
在調用$ this-> User-> save()之前,如果您執行$ this-> log($ this-> data),您會顯示什麼? – user470714 2011-03-29 22:35:38
我已經在問題中編寫了日誌。感謝您的提示,這對調試非常有用! – vitto 2011-03-29 23:23:30