zone_g@163.com

zone_g@163.com

这家伙有点懒,还没写个性签名!

  • 财富值174
  • 威望值10
  • 总积分374

个人信息

  • 2015-04-14 已签到
    连续签到4天,获得了20个金钱
  • 2015-04-13 已签到
    连续签到3天,获得了15个金钱
  • 2015-04-12 已签到
    连续签到2天,获得了10个金钱
  • 控制器判断是否ajax提交可以使用

    \Yii::$app->request->isAjax(2.0)
    Yii::app()->request->isAjaxRequest (1.*)
    
  • 问题找到了,但是是个很奇怪的问题,调用类下的函数时返回的是false,但是在调用的这个函数内部返回的确实true...不解

    public function validatePassword($password, $hash)
        {
            if (!is_string($password) || $password === '') {
                throw new InvalidParamException('Password must be a string and cannot be empty.');
            }
    
            if (!preg_match('/^\$2[axy]\$(\d\d)\$[\.\/0-9A-Za-z]{22}/', $hash, $matches) || $matches[1] < 4 || $matches[1] > 30) {
                throw new InvalidParamException('Hash is invalid.');
            }
    
            switch ($this->passwordHashStrategy) {
                case 'password_hash':
                    if (!function_exists('password_verify')) {
                        throw new InvalidConfigException('Password hash key strategy "password_hash" requires PHP >= 5.5.0, either upgrade your environment or use another strategy.');
                    }
                    return password_verify($password, $hash);
                case 'crypt':
                    $test = crypt($password, $hash);
                    $n = strlen($test);
                    if ($n !== 60) {
                        return false;
                    }
                    
                    var_dump($this->compareString($test, $hash));//false
                    die();
                    
                    return $this->compareString($test, $hash);
                default:
                    throw new InvalidConfigException("Unknown password hash strategy '{$this->passwordHashStrategy}'");
            }
        }
    
    public function compareString($expected, $actual)
        {
            $expected .= "\0";
            $actual .= "\0";
            $expectedLength = StringHelper::byteLength($expected);
            $actualLength = StringHelper::byteLength($actual);
            $diff = $expectedLength - $actualLength;
            for ($i = 0; $i < $actualLength; $i++) {
                $diff |= (ord($actual[$i]) ^ ord($expected[$i % $expectedLength]));
            }
            return $diff === 0;//true
        }
    

    Security这个类里面,很郁闷

  • 2015-04-11 已签到
    连续签到1天,获得了5个金钱
见习主管 等级规则
374/500
资料完整度
40/100
用户活跃度
0/100

Ta的关注

1

Ta的粉丝

2

Ta的访客

4