【问题标题】:Cakephp & user email confirmationCakephp 和用户电子邮件确认
【发布时间】:2014-09-21 12:32:42
【问题描述】:

我是 php 和 cakephp 的新手,我正在学习 cakephp (http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html) 的简单身份验证和授权应用程序教程。一切似乎都运行良好。

当用户订阅时,我将添加一封电子邮件确认以激活帐户。在本教程中,密码使用的是 blowfishpassword 哈希器。我将它用作链接中的令牌以进行确认。

但我似乎无法将链接令牌与数据库中的密码进行比较...

$passwordHasher = new BlowfishPasswordHasher();
            $motdepasse = $this->data['Utilisateur']['mot_passe'] = $passwordHasher->hash(
                $this->data['Utilisateur']['mot_passe']
            );
            $link = array('controller'=>'utilisateurs','action'=>'activate',$this->Utilisateur->id
                  .'-'. $motdepasse);


public function activate($token) {
  $token = explode('-',$token);
  $user = $this->Utilisateur->find('first',array(
    'conditions' => array('id' => $token[0],'Utilisateur.mot_passe' => Security::hash($token[1], 'blowfish', 'Utilisateur.mot_passe'))
  ));
  debug($user);
  debug($token[1]);
  die();

}

你能帮帮我吗?谢谢大家!

【问题讨论】:

  • Wince 你是手动做的,你能检查一下每个的散列版本是什么,看看它们是否真的不同?

标签: cakephp


【解决方案1】:

首先,您不应该发送密码哈希,无论哈希可能多么安全,都应该单独生成确认令牌!只需将其存储在额外的列或单独的表中即可。

话虽如此,在您的 activate() 方法中,您再次对哈希进行哈希处理,如果实际生成哈希,则会导致比较失败。但是,该脚本不会生成哈希,因为您使用了无效的盐值,这将导致以下警告:

无效盐:河豚的 Utilisateur.mot_passe 请访问 http://www.php.net/crypt 并阅读有关构建河豚盐的相应部分。

Security::hash() 将返回一个空字符串。如果你没有收到这样的消息,那么你需要enable the debug mode

我建议在尝试实现安全相关功能之前先熟悉 PHP、CakePHP、哈希和其他东西!

您可能想查看 https://github.com/CakeDC/users,它支持电子邮件验证和更多开箱即用的功能。

【讨论】:

猜你喜欢
  • 2021-06-16
  • 1970-01-01
  • 2018-12-24
  • 2017-06-12
  • 2020-06-23
  • 1970-01-01
  • 2011-01-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多