他的意思是在數據庫中存儲原始的「John」,然後在登錄表單中輸入數據庫保存的值以及輸入的名稱。然後,您仍然擁有與註冊方式相同的用戶名。
實施例加了:
Login.ctp
echo $this->Form->create('User', array('url' => array('controller' => 'users', 'action' => 'register')));
echo $this->Form->input('User.username', array('label' => 'First Name:'));
echo $this->Form->input('User.password', array('label' => 'Password', 'type' => 'password', 'value' => false));
echo $this->Form->submit('Register');
echo $this->Form->end();
考慮到當用戶輸入存在的用戶名和密碼。假設我使用用戶名「John」。大寫字母J就是我們想要確保數據庫中的內容。保存數據時我們不會使用strtolower。所以通過使用一個cake的save()方法,我們可以完成保存你的大小寫敏感問題。
register.ctp
public function register()
{
if ($this->Auth->loggedIn()) {
$this->redirect(array('controller' => 'users', 'action' => 'login'));
}
if ($this->request->is('post')) {
if ($this->User->User->saveAll($this->request->data)
{
$this->Session->setFlash(__('Your account has been created', true));
$this->redirect(array('controller' => 'users', 'action' => 'index'));
}}
現在,當我們登錄操作:
if ($this->request->is('post')) {
if ($this->Auth->loggedIn()) {
$logged = $this->User->query('Your sql query matching username/password with strtolower, if you need to implement security hash from cakephp you can do that through cakephp hash method');
}
}
基本的例子,但它應該幫助
只是使用正確的數據庫排序規則,您將始終有不區分大小寫的查詢,例如, utf8_unicode_ci(ci代表正是這樣) – mark 2012-07-17 07:50:14