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


PHP UserDAO::userExists方法代碼示例

本文整理匯總了PHP中UserDAO::userExists方法的典型用法代碼示例。如果您正苦於以下問題:PHP UserDAO::userExists方法的具體用法?PHP UserDAO::userExists怎麽用?PHP UserDAO::userExists使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在UserDAO的用法示例。


在下文中一共展示了UserDAO::userExists方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: login

 /** 
  * Attempts to login with username and password.
  * 
  * @param string $username Username
  * @param string $password Password
  * @return bool True if login was successful, or false otherwise.
  */
 public function login($username, $password)
 {
     $dao = new UserDAO();
     if ($dao->userExists($username)) {
         $pwhash = $dao->getPassword($username);
         if (pw_verify($password, $pwhash)) {
             $this->loggedIn = true;
             $this->username = $username;
             return true;
         }
     }
     return false;
 }
開發者ID:Replica94,項目名稱:SysProjE,代碼行數:20,代碼來源:User.class.php

示例2: password

     $passwd2 = $_POST['passwd2'];
     $username = $_POST['username'];
     // validate password and username
     if ($passwd != $passwd2) {
         $warnings[] = "Passwords don't match";
     }
     if (!isValidPassword($passwd)) {
         $warnings[] = "Not a valid password (longer than " . MIN_PASSWORD_LENGTH . " characters required)";
     }
     if (!isValidUsername($username)) {
         $warnings[] = "Not a valid username (longer than " . MIN_USERNAME_LENGTH . " characters required)";
     }
     // No warnings means everything is in order, and we can create the user
     if (count($warnings) == 0) {
         $dao = new UserDAO();
         if ($dao->userExists($username)) {
             $warnings[] = "Username already taken";
         } else {
             $passwd = pw_encode($passwd);
             if (!$dao->createUser($username, $passwd)) {
                 $warnings[] = "Failed to insert to database";
             } else {
                 // Registration was successful, redirect the user to
                 // the login screen
                 $session->set('register_flag', true);
                 header("Location: login.php");
                 exit;
             }
         }
     }
 }
開發者ID:Replica94,項目名稱:SysProjE,代碼行數:31,代碼來源:register.php


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