/** * Function to be run before every test*() functions. */ public function setUp() { BasicPasswordManagement::$hashAlgo = "haval256,5"; //choose salting algo. User::newUserObject("rash", 'testing', "*****@*****.**"); //create a user. User::activateAccount("rash"); //activate the user account $this->user = User::existingUserObject("rash", "testing"); //get the user object $this->obj = new AdvancedPasswordManagement($this->user->getUserID(), 'testing'); //create object to AdvancedPasswordManagement class. }
/** * Function to be run before every test*() functions. */ public function setUp() { BasicPasswordManagement::$hashAlgo = "haval256,5"; //choose a hashing algo. User::newUserObject("rash", 'testing', "*****@*****.**"); //create a new user. User::activateAccount("rash"); //activate the user account $this->obj = User::existingUserObject("rash", "testing"); //get the user object $this->xobj = new XUser($this->obj); //get the XUser object }
/** * To check if we can generate a random string of given strength. */ public function testGenerate() { $this->assertEquals(4, strlen(BasicPasswordManagement::generate(0.1))); $this->assertEquals(8, strlen(BasicPasswordManagement::generate(0.4))); $this->assertEquals(16, strlen(BasicPasswordManagement::generate(0.8))); }
/** * Function to force to change the password, even when the user has not provided the old password for verification. Used with "forgot password controller". * If the user forgets his password, they need to be validated using their primary email. Once that is done, the user would like to keep a new password. This function will help there to keep a new password. * @param string $newPassword * @return boolean Returns TRUE when the password has been changed successfully */ public function forceResetPassword($newPassword) { //create a new dynamic salt. $this->dynamicSalt = hash(BasicPasswordManagement::$hashAlgo, randstr(128)); //create the hash of the new password. $newHash = BasicPasswordManagement::hashPassword($newPassword, $this->dynamicSalt, BasicPasswordManagement::$hashAlgo); //update the old password with the new password. SQL("UPDATE USER SET `HASH` = ?, `DATE_CREATED` = ?, `DYNAMIC_SALT` = ?, `ALGO` = ? WHERE `USERID` = ?", array($newHash, time(), $this->dynamicSalt, BasicPasswordManagement::$hashAlgo, $this->userID)); $this->hashedPassword = $newHash; $this->hashAlgorithm = BasicPasswordManagement::$hashAlgo; return TRUE; }
/** * Function to test if allows to create a user with an Null ID * @expectedException phpsec\UserIDInvalid */ public function testUserIDNull() { BasicPasswordManagement::$hashAlgo = "haval256,5"; //choose a hashing algo User::newUserObject(null, 'testing', "*****@*****.**"); //create a new user }