1
我正在開發一個使用cakephp 2.3.9的應用程序。它有一個用戶表來保存用戶的憑證。我如何在表中使用除password
以外的其他field
字段來保存密碼。cakephp自定義密碼字段
我正在開發一個使用cakephp 2.3.9的應用程序。它有一個用戶表來保存用戶的憑證。我如何在表中使用除password
以外的其他field
字段來保存密碼。cakephp自定義密碼字段
你可以試試這個:
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()
功能也通過適當的檢查。
編號:
非常感謝你爲你的立即答覆。我嘗試過了,它幾乎工作,但多了一個我正面臨的問題是我不想加密該自定義密碼字段。所以我如何處理它..你有什麼想法嗎? – Arun
@ user2575428請檢查更新答案 – thecodeparadox