コード例 #1
0
ファイル: Handler.php プロジェクト: IMPHP/libimphp
 public function write(string $data) : bool
 {
     $status = false;
     if (Database::isConnected()) {
         $time = time();
         if ($this->mUpdate) {
             $status = Database::update("sessions")->field("cData", "s", $data)->field("cTime", "i", time())->cond("cSessId", "s", $this->mSessId)->execute() > 0;
         } else {
             $status = Database::insert("sessions")->field("cData", "s", $data)->field("cTime", "i", time())->field("cSessId", "s", $this->mSessId)->execute() > 0;
         }
     }
     Runtime::removeLock("database");
     return $status;
 }
コード例 #2
0
ファイル: User.php プロジェクト: IMPHP/libimphp
 public function login(string $username, string $password) : bool
 {
     $chkName = strtolower($username);
     if ($this->mUserId == 0 && !empty($username) && !empty($password)) {
         if ($chkName == "root") {
             $rootPasswd = Runtime::$SETTINGS["AUTH_ROOT_PASSWD"];
             if (!empty($rootPasswd) && password_verify($password, $rootPasswd)) {
                 $this->mUserId = -1;
                 $this->mUserName = "******";
                 $this->mUserGroups = null;
                 Runtime::$SESSION["_im_userid"] = $this->mUserId;
                 return true;
             }
         } elseif ($chkName != "guest") {
             if (Database::isConnected()) {
                 $result = Database::select("users")->fields("cName", "cPassword", "cId")->cond("cName", "s", $username)->enquire();
                 if ($result !== null) {
                     if ($result->numRows() > 0) {
                         $row = $result->fetchAssoc();
                         if ($row !== null && password_verify($password, $row["cPassword"])) {
                             $algo = Runtime::$SETTINGS->getInt("AUTH_VERIFY_ALGO", PASSWORD_DEFAULT);
                             $options = Runtime::$SETTINGS->getArray("AUTH_VERIFY_OPTIONS", []);
                             /*
                              * Hash settings has changed, update password
                              */
                             if (password_needs_rehash($row["cPassword"], $algo, $options)) {
                                 $hash = password_hash($password, $algo, $options);
                                 Database::update("users", "cPassword", "cId=?", "si", $hash, $row["cId"]);
                             }
                             $this->mUserId = $row["cId"];
                             $this->mUserName = $row["cName"];
                             $this->mUserGroups = null;
                             Runtime::$SESSION["_im_userid"] = $this->mUserId;
                         }
                     }
                     $result->destroy();
                 }
                 return $this->mUserId != 0;
             }
         }
     }
     return false;
 }