本文整理汇总了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));
}
示例2: testCompare
public function testCompare()
{
$this->assertTrue(String::compare('Foo', 'Foo'));
$this->assertFalse(String::compare('Foo', 'foo'));
$this->assertFalse(String::compare('1', 1));
}
示例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;
}
示例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.');
}
示例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');
});
}
示例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);
}