本文整理匯總了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;
}