1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace PHPassLib\Test\Application;
13:
14: use PHPassLib\Application\Context;
15: use PHPassLib\Exception\RuntimeException;
16:
17: 18: 19: 20: 21: 22: 23: 24:
25: class ContextTest extends \PHPUnit_Framework_TestCase
26: {
27:
28: 29: 30:
31: public function contextCanVerifyMultipleConfigurations()
32: {
33: $context = new Context;
34: $context->addConfig('bcrypt');
35: $context->addConfig('pbkdf2');
36:
37: $this->assertTrue($context->verify('password', '$2a$12$m8BI4QL9ALnhIspk70ZQ..xiSX2CHw2r0IZB4EAmV59vJ/1NOQNoy'));
38: $this->assertTrue($context->verify('password', '$pbkdf2$12000$VOK/VpoqrPyLwl256fbq9A$GMLWbZHcx1cSeKv8vqMkro424T4'));
39:
40: $exception = null;
41: try {
42: $context->verify('password', '$1$Gwzk6VAb$0b.FnV/z3WV7JsdT0JUMT1');
43: } catch (RuntimeException $exception) {
44: }
45:
46: $this->assertInstanceOf('PHPassLib\\Exception', $exception);
47: }
48:
49: 50: 51:
52: public function contextUsesFirstConfigForHashing()
53: {
54: $context = new Context;
55: $context->addConfig('bcrypt');
56: $context->addConfig('pbkdf2');
57:
58: $this->assertStringStartsWith('$2a$', $context->hash('password'));
59: }
60:
61: 62: 63:
64: public function contextIdentifiesOutdatedHashes()
65: {
66: $context = new Context;
67: $context->addConfig('pbkdf2', array ('digest' => 'sha1'));
68: $context->addConfig('bcrypt');
69:
70: $this->assertFalse($context->needsUpdate('$pbkdf2$12000$3XWNbVbeGaE/6PD2D/fPMA$5ePab2Y6zuxk.grl5Yo/QvgNrlY'));
71: $this->assertTrue($context->needsUpdate('$pbkdf2$10000$27ERFDenq28ObTH/QcxsAw$YIU6k8STkdoJ5qE2L47TaTYistA'));
72: $this->assertTrue($context->needsUpdate('$2a$12$TeRU2URC/eV2z3qVoViiR.kYSqjQ4pMgOqycTSANspO.6IN8TNOHq'));
73: }
74:
75: }
76: