duanqinqiao4844 2013-12-06 18:29
浏览 23
已采纳

Zend表单旧密码验证

How can i check if a specific record exists with Zend_Validate_Db_RecordExists?

Here is my code, i want to match old password before user changes it

 $oldpassexist = new Zend_Validate_Db_RecordExists(array(
            'table' => 'user',
            'field' => 'password',
                /** check if password matches
                 *  WHERE user_id = Auth::getuser()->id AND password = md5(THIS FIELD ENTRY) 
                 */
        ));
  • 写回答

2条回答 默认 最新

  • dpnfxk251524 2013-12-08 09:11
    关注

    Adding another where clause is pretty easy. Zend_Validate_Db_RecordExists allows you to modify the Zend_Db_Select object that it uses internally. So you could write:

    $oldpassexist = new Zend_Validate_Db_RecordExists(array(
            'table' => 'user',
            'field' => 'password',
        ));
    
    // reset the where clause used by Zend_Validate_Db_RecordExists
    $oldpassexist->getSelect()->reset('where');
    
    // set user_id and password. :value is a named parameter that will be 
    // substituted by the value passed to the isValid method
    $oldpassexist->getSelect()->where('user_id = ?', Auth::getuser()->id);
    $oldpassexist->getSelect()->where('password = MD5(:value)');
    

    Which will query both the password as hashed MD5 as well as the user_id field. However, I think this solution is not really elegant. I would probably write my own Validator for this. In any case you should write thorough test cases to detect if the behavior of Zend_Validate_Db_RecordExists changes one day.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序