當前位置: 首頁>>代碼示例>>PHP>>正文


PHP UserClient::setUserObject方法代碼示例

本文整理匯總了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;
 }
開發者ID:Janste,項目名稱:PHP_MVC_Simple_Social_Network,代碼行數:34,代碼來源:Authentication.php


注:本文中的UserClient::setUserObject方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。