当前位置: 首页>>代码示例>>PHP>>正文


PHP String::compare方法代码示例

本文整理汇总了PHP中lithium\util\String::compare方法的典型用法代码示例。如果您正苦于以下问题:PHP String::compare方法的具体用法?PHP String::compare怎么用?PHP String::compare使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在lithium\util\String的用法示例。


在下文中一共展示了String::compare方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: check

 /**
  * Compares a password and its hashed value using PHP's `crypt()`. Rather than a simple string
  * comparison, this method uses a constant-time algorithm to defend against timing attacks.
  *
  * @see lithium\security\Password::hash()
  * @see lithium\security\Password::salt()
  * @param string $password The user-supplied plaintext password to check.
  * @param string $hash The known hashed password to compare it to.
  * @return boolean Returns a boolean indicating whether the password is correct.
  */
 public static function check($password, $hash)
 {
     return String::compare($hash, crypt($password, $hash));
 }
开发者ID:fedeisas,项目名称:lithium,代码行数:14,代码来源:Password.php

示例2: testCompare

 public function testCompare()
 {
     $this->assertTrue(String::compare('Foo', 'Foo'));
     $this->assertFalse(String::compare('Foo', 'foo'));
     $this->assertFalse(String::compare('1', 1));
 }
开发者ID:newmight2015,项目名称:Blockchain-2,代码行数:6,代码来源:StringTest.php

示例3: read

 /**
  * Read strategy method.
  * Validates the HMAC signature of the stored data. If the signatures match, then
  * the data is safe, and the 'valid' key in the returned data will be
  *
  * If the store being read does not contain a `__signature` field, a `MissingSignatureException`
  * is thrown. When catching this exception, you may choose to handle it by either writing
  * out a signature (e.g. in cases where you know that no pre-existing signature may exist), or
  * you can blackhole it as a possible tampering attempt.
  *
  * @param array $data the Data being read.
  * @param array $options Options for this method.
  * @return array validated data
  */
 public function read($data, array $options = array())
 {
     $class = $options['class'];
     $currentData = $class::read(null, array('strategies' => false));
     if (!isset($currentData['__signature'])) {
         throw new MissingSignatureException('HMAC signature not found.');
     }
     $currentSignature = $currentData['__signature'];
     $signature = static::_signature($currentData);
     if (!String::compare($signature, $currentSignature)) {
         $message = "Possible data tampering: HMAC signature does not match data.";
         throw new RuntimeException($message);
     }
     return $data;
 }
开发者ID:newmight2015,项目名称:Blockchain-2,代码行数:29,代码来源:Hmac.php

示例4: read

 /**
  * Read strategy method.
  *
  * Validates the HMAC signature of the stored data. If the signatures match, then the data
  * is safe and will be passed through as-is.
  *
  * If the stored data being read does not contain a `__signature` field, a
  * `MissingSignatureException` is thrown. When catching this exception, you may choose
  * to handle it by either writing out a signature (e.g. in cases where you know that no
  * pre-existing signature may exist), or you can blackhole it as a possible tampering
  * attempt.
  *
  * @throws RuntimeException On possible data tampering.
  * @throws lithium\storage\session\strategy\MissingSignatureException On missing singature.
  * @param array $data The data being read.
  * @param array $options Options for this method.
  * @return array Validated data.
  */
 public function read($data, array $options = array())
 {
     if ($data === null) {
         return $data;
     }
     $class = $options['class'];
     $currentData = $class::read(null, array('strategies' => false));
     if (!isset($currentData['__signature'])) {
         throw new MissingSignatureException('HMAC signature not found.');
     }
     if (String::compare($currentData['__signature'], static::_signature($currentData))) {
         return $data;
     }
     throw new RuntimeException('Possible data tampering: HMAC signature does not match data.');
 }
开发者ID:unionofrad,项目名称:lithium,代码行数:33,代码来源:Hmac.php

示例5: testCompare

 public function testCompare()
 {
     $this->assertTrue(String::compare('Foo', 'Foo'));
     $this->assertFalse(String::compare('Foo', 'foo'));
     $this->assertFalse(String::compare('Foo', 'Bar'));
     $this->assertTrue(String::compare('', ''));
     $this->assertFalse(String::compare('', '0'));
     $this->assertFalse(String::compare('0', ''));
     $this->assertException('/to be (a )?string/', function () {
         String::compare(null, null);
     });
     $this->assertException('/to be (a )?string/', function () {
         String::compare(null, '');
     });
     $this->assertException('/to be (a )?string/', function () {
         String::compare('', null);
     });
     $this->assertTrue(String::compare('1', '1'));
     $this->assertException('/to be (a )?string/', function () {
         String::compare('1', 1);
     });
     $this->assertException('/to be (a )?string/', function () {
         String::compare(1, '1');
     });
 }
开发者ID:fedeisas,项目名称:lithium,代码行数:25,代码来源:StringTest.php

示例6: testCompare

 public function testCompare()
 {
     $backup = error_reporting();
     error_reporting(E_ALL);
     $this->assertTrue(String::compare('Foo', 'Foo'));
     $this->assertFalse(String::compare('Foo', 'foo'));
     $this->assertFalse(String::compare('Foo', 'Bar'));
     $this->assertTrue(String::compare('', ''));
     $this->assertFalse(String::compare('', '0'));
     $this->assertFalse(String::compare('0', ''));
     $this->assertException('/to be (a )?string/', function () {
         String::compare(null, null);
     });
     $this->assertException('/to be (a )?string/', function () {
         String::compare(null, '');
     });
     $this->assertException('/to be (a )?string/', function () {
         String::compare('', null);
     });
     $this->assertTrue(String::compare('1', '1'));
     $this->assertException('/to be (a )?string/', function () {
         String::compare('1', 1);
     });
     $this->assertException('/to be (a )?string/', function () {
         String::compare(1, '1');
     });
     error_reporting($backup);
 }
开发者ID:unionofrad,项目名称:lithium,代码行数:28,代码来源:StringTest.php


注:本文中的lithium\util\String::compare方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。