【问题标题】:Use authentication against encrypted password对加密密码使用身份验证
【发布时间】:2014-05-30 14:44:01
【问题描述】:

我的密码在数据库中被 zend2BlockCipher 加密:

 public function cipher($incKey, $password) {

        $cipher = BlockCipher::factory ( 'mcrypt', array (
                'algorithm' => 'aes'
        ));

        $cipher->setKey ( $incKey );
        $text = $password;

        $encrypted = $cipher->encrypt ( $text );

        echo "Encrypted text: $encrypted \n";
        return $encrypted;

    }

现在我需要在登录时验证用户的密码:

$cipher = new Cipher();

$ciphered_password = $cipher->cipher($incKey, $data['usr_password']);

$authAdapter = new AuthAdapter($dbAdapter,
        'users', 
        'email',
        'password', 
        "CONCAT('$ciphered_password') AND state= 1"
        );

但是没有通过认证;

使用代码:FAILURE_CREDENTIAL_INVALID

我在这里做错了吗?

任何帮助将不胜感激。

【问题讨论】:

    标签: php authentication encryption passwords zend-framework2


    【解决方案1】:

    Blockcipher::factory 使用的加密模式不是确定性的。 It uses CBC 使用随机 IV 初始化,因此每个密文(加密明文)看起来都不同且是伪随机的。您应该改用密码散列This page 似乎是它在 zend 中的合适资源。在 security.se 你可以找到一些background knowledge to password storage

    【讨论】:

    • 重要的是如何添加 CONCAT('$ciphered_pa​​ssword') 来工作
    • @GingerHead:我不明白这怎么可能。基本上你正在做的是这个$password=$data['usr_password']; $ciphered_password=getRandom(); compareAgainstDatabase($ciphered_password)
    • 如果我只需要使用 base 64 进行编码怎么办?
    • @GingerHead,在问如何用 base64 编码替换加密?你想解决什么问题?您想为可以选择自己密码的用户提供登录名,然后您需要验证他们确实再次提供了正确的密码吗?然后password hashing 真的是正确的方法。它避免了密码中的非法字符、数据库列密码过长等问题,是针对数据库泄露问题的第一个也是最简单的安全增强。
    • 它在保存到数据库之前将密码编码为base 64?
    猜你喜欢
    • 1970-01-01
    • 2015-12-28
    • 1970-01-01
    • 2022-12-16
    • 1970-01-01
    • 2018-09-11
    • 2011-05-08
    • 1970-01-01
    • 2020-02-28
    相关资源
    最近更新 更多