It deals with hashing and verifying passwords according to specific configurable strategies, so that different types of password hashing methods can be used in the same model. This is useful if you have an existing system that uses e.g. unsalted md5 and you want to upgrade to a more secure system like bcrypt. When users using the legacy md5 passwords log in, their password will automatically be rehashed using the new bcrypt strategy.
<?php
Yii::import("application.components.YiiPassword.*");
Yii::import("application.models.*");
/**
* Tests for the {@link ABcryptPasswordStrategy} class.
* @author Charles Pick
* @package packages.passwordStrategy
*/
class ABcryptPasswordStrategyTest extends CTestCase
{
public function testEncode()
{
$strategy = new ABcryptPasswordStrategy();
$strategy->getSalt(true);
$password = "qwerty1";
$this->assertFalse($strategy->compare("test",$strategy->encode($password)));
$this->assertTrue($strategy->compare("qwerty1",$strategy->encode($password)));
$user=User::model()->findByAttributes(array('username'=>'user'));
$strategy = new ABcryptPasswordStrategy();
$strategy->getSalt(true);
}
}
Now in Test i get following error:
There was 1 error:
1) ABcryptPasswordStrategyTest::testEncode
CException: Alias "packages.passwordStrategy.*" is invalid. Make sure it points to an existing directory or file.
C:\Apache2\htdocs\yii\framework\YiiBase.php:343
C:\Apache2\htdocs\x\protected\components\YiiPassword\APasswordBehavior.php:2
C:\Apache2\htdocs\yii\framework\YiiBase.php:423
C:\Apache2\htdocs\yii\framework\YiiBase.php:298
C:\Apache2\htdocs\yii\framework\YiiBase.php:198
C:\Apache2\htdocs\yii\framework\base\CComponent.php:327
C:\Apache2\htdocs\yii\framework\base\CComponent.php:298
C:\Apache2\htdocs\yii\framework\db\ar\CActiveRecord.php:389
C:\Apache2\htdocs\x\protected\models\User.php:28
C:\Apache2\htdocs\x\protected\tests\unit\ABcryptPasswordStrategyTest.php:22
C:\php\phpunit:46
FAILURES!
Tests: 1, Assertions: 2, Errors: 1.