我保存了密码如下:
function hashPassword() {
if (!empty($this->data[$this->alias]['password'])) {
$passwordHasher = new SimplePasswordHasher(array('hashType' => 'sha256'));
$this->data[$this->alias]['password'] = $passwordHasher->hash(
$this->data[$this->alias]['password']
);
}
}
function setIP() {
/* IP address insert */
$exec = exec("hostname"); //the "hostname" is a valid command in both windows and linux
$hostname = trim($exec); //remove any spaces before and after
$ip = gethostbyname($hostname); //resolves the hostname using local hosts resolver or DNS
$this->data['User']['ip'] = $ip;
}
function beforeSave($options = array()) {
$this->hashPassword();
$this->setIP();
return true;
}
现在我怎么能将这个密码显示为纯文本。即:以下代码检索用户表的所有信息:
function manage_user() {
$this->loadModel('User');
$users = $this->User->find('all');
$this->set(compact('users'));
}
但是密码是哈希格式,我怎么能把它作为纯文本? 任何建议将不胜感激。
答案 0 :(得分:3)
哈希的全部意义在于您无法对密码进行反向工程。因此,当您的数据库被黑客入侵或泄露时,不会对密码造成任何伤害。
任何显示您自己密码的网站都存在严重的安全问题,我不会使用它。
所以答案是:不,你不能,你不应该