当前位置: 首页>>代码示例>>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;未经允许,请勿转载。