2013-11-01 31 views
1

我正在開發一個使用cakephp 2.3.9的應用程序。它有一個用戶表來保存用戶的憑證。我如何在表中使用除password以外的其他field字段來保存密碼。cakephp自定義密碼字段

回答

2

你可以試試這個:

public $components = array(
    'Auth' => array(
     'loginAction' => array(
      ...... 
     ), 
     'authError' => '...', 
     'authenticate' => array(
      'Form' => array(
       'fields' => 
        array(
         'password' => 'YOUR_CUSTOM_FIELD' // set custom field 
                 // as password field 
        ) 
      ) 
     ) 
    ) 
); 
AppController.php

並在您的表單集type="password"到該字段。例如

$this->Form->input('YOUR_CUSTOM_FIELD', array('type' => 'password')); 

引用comment,你需要做的手工方法在您的控制器或模型中的密碼字段進行加密。例如在控制器,你可以這樣做:

$this->request->data['User']['YOUR_CUSTOM_FIELD'] = AuthComponent::password($this->request->data['User']['YOUR_CUSTOM_FIELD']); 

您也可以在add/edit訴訟案做模型beforeSave()功能也通過適當的檢查。


編號:

  1. CakePHP Auth Password Hash
  2. For detail about CakePHP Auth
+0

非常感謝你爲你的立即答覆。我嘗試過了,它幾乎工作,但多了一個我正面臨的問題是我不想加密該自定義密碼字段。所以我如何處理它..你有什麼想法嗎? – Arun

+0

@ user2575428請檢查更新答案 – thecodeparadox