當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。