本文整理汇总了PHP中UserClient::setUserObject方法的典型用法代码示例。如果您正苦于以下问题:PHP UserClient::setUserObject方法的具体用法?PHP UserClient::setUserObject怎么用?PHP UserClient::setUserObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserClient
的用法示例。
在下文中一共展示了UserClient::setUserObject方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authenticate
/**
* Checks if credentials typed by the user are ok.
* If credentials are incorrect or something is missing it
* sets proper output message
* @param $u, which is username
* @param $p, which is password
* @param $userClient
* @return true is credentials are correct and false if otherwise
*/
private function authenticate($u, $p, UserClient $userClient)
{
if (empty($u)) {
// Check is username field is empty
return false;
} elseif (empty($p)) {
// Check is password field is empty
return false;
}
$amount = count($this->users);
// Loop through all users and check if there exists a user with specified username and password
for ($i = 0; $i < $amount; $i++) {
$username = $this->users[$i]->getUsername();
// Get username from array
$hashedPassword = $this->users[$i]->getPassword();
// Get hashed password from user array
if ($username == $u && password_verify($p, $hashedPassword)) {
// Check if credentials are correct
$userClient->setUserObject($this->users[$i]);
$_SESSION[self::$sessionUserLocation] = $userClient;
return true;
}
}
return false;
}