Example #1
0
 public function addToken($gid, $token)
 {
     if (!file_exists($this->path)) {
         $handle = fopen($this->path, 'w');
         fclose($handle);
         $content = array();
     } else {
         $handle = fopen($this->path, 'r+');
         while (!flock($handle, LOCK_EX)) {
             // Wait for file lock
             usleep(100);
         }
         clearstatcache();
         $size = filesize($this->path);
         $content = array();
         if ($size > 0) {
             $json = fread($handle, $size);
             $content = json_decode($json, true);
             if (!is_array($content)) {
                 $content = array();
             }
         }
     }
     $token = $this->hashFunction->calculatePasswordHash($token, $this->costFactor, $this->hmacKey);
     $content[] = array('gid' => $gid, 'token' => $token);
     $content = json_encode($content);
     if (is_string($content)) {
         ftruncate($handle, 0);
         fseek($handle, 0, SEEK_SET);
         fwrite($handle, $content);
     }
     flock($handle, LOCK_UN);
     fclose($handle);
 }
 public function update($gid, $data)
 {
     assert(isset($data['password']));
     $hash = $this->hashFunction->calculatePasswordHash($data['password'], $this->costFactor, $this->hmacKey);
     $this->storage->update($gid, $hash);
 }