Zend 2表格旧密码验证

时间:2015-10-29 08:20:54

标签: php zend-framework md5

我在DB中的密码使用MD5加密,如何检查MD5是否存在特定记录并使用\ Zend \ Validator \ Db \ RecordExists?

'validators' => array(

                        array(
                                'name' => '\Zend\Validator\Db\RecordExists',
                                'options' => array(
                                        'table' => 'users',
                                        'field' => 'password',
                                        'adapter' => $this->dbAdapter,

                                        'messages' => array(
                                                \Zend\Validator\Db\RecordExists::ERROR_NO_RECORD_FOUND=> 'Password not match',
                                        ),
                                ),
                ),

1 个答案:

答案 0 :(得分:0)

根据zend文档,你可以这样试试:

//Validator declaration but the way you used it should work too.
$validator = new Zend_Validate_Db_RecordExists(
    array(
        'table' => 'users',
        'field' => 'password',
        'adapter' => $this->dbAdapter,
    )
);

if ($validator->isValid($recordToCheck)) {
    // Password exists
} else {
    // Password does not exists and we display the error message
    foreach ($validator->getMessages() as $message) {
        echo 'Password not match';
    }
} 

希望它会有所帮助