如何在cakephp 3中手动进行密码散列?

时间:2015-12-11 04:50:22

标签: hash cakephp-3.0

我正在处理忘记密码,我想使用rand()发送新密码。将密码发送到客户电子邮件后,我想用哈希更新新密码,但我不知道怎么做?请帮帮我解决这个问题?

代码:

didFindScenarios: function(recs){
  recs.forEach (function (rec) {
    Ember.run.once (this, function() {
        rec.destroyRecord();
    });
  });
  this.set('isProcessing', false); //we have the 'this' that refers to this application controller since we called `.bind(this)` on this function
},

didNotFindScenarios: function(err){
  console.log ('findAll Scenario failed. Here is the error: ' + err);
  this.set('isProcessing', false);
},

actions: {
  deleteAllScenarios: function(){
      this.set('isProcessing', true); //just an example using 'this'
      this.store.findAll('scenario').then(this.didFindScenarios.bind(this), this.didNotFindScenarios.bind(this));
  },
}
  

错误:Class' App \ Controller \ Security'找不到

1 个答案:

答案 0 :(得分:7)

只需在控制器中使用以下行。

use Cake\Auth\DefaultPasswordHasher;

现在,您可以使用以下代码手动哈希密码。

$password = "Your Password";
$hasher = new DefaultPasswordHasher();
$hasher->hash($password);