Add password management and the associated tests
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4137 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
49
Tests/passwordTest.php
Normal file
49
Tests/passwordTest.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/** Test the password class
|
||||
*/
|
||||
class test_password extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_cryptPasswd_1 ()
|
||||
{
|
||||
$res = \password::cryptPasswd ("AAA");
|
||||
$this->assertSame (substr ($res, 0, 4), "$2y$");
|
||||
}
|
||||
|
||||
public function test_cryptPasswd_2 ()
|
||||
{
|
||||
// Test the randomization of the salt : must be different each time
|
||||
$res1 = \password::cryptPasswd ("AAA");
|
||||
echo "RES1=$res1\n";
|
||||
$res2 = \password::cryptPasswd ("AAA");
|
||||
echo "RES2=$res2\n";
|
||||
$res3 = \password::cryptPasswd ("AAA");
|
||||
echo "RES3=$res3\n";
|
||||
$this->assertSame (count (array_unique (array ($res1, $res2, $res3))), 3);
|
||||
// Three passwords : each must have a different result
|
||||
}
|
||||
|
||||
public function test_checkPassword_1 ()
|
||||
{
|
||||
$res = \password::checkPassword ("AAA", "AAA");
|
||||
$this->assertSame ($res, false);
|
||||
}
|
||||
|
||||
public function test_checkPassword_2 ()
|
||||
{
|
||||
$res = \password::checkPassword ("AAA", \password::cryptPasswd ("AAA"));
|
||||
$this->assertSame ($res, true);
|
||||
}
|
||||
|
||||
public function test_checkPassword_3 ()
|
||||
{
|
||||
$res = \password::checkPassword ("AAA", \password::cryptPasswd ("BBB"));
|
||||
$this->assertSame ($res, false);
|
||||
}
|
||||
|
||||
public function test_checkPassword_4 ()
|
||||
{
|
||||
$res = \password::checkPassword ("AAA",
|
||||
'$2y$11$Y.E98jbjgDpV61eK..9MT.klzTeg7ulO4WH/B5yA8cAGMIh.zoNXq');
|
||||
$this->assertSame ($res, true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user