示例#1
0
文件: Plain.php 项目: PGoski/SOCKS5
 public function authenticate(Client $client)
 {
     $login_string = pack('CC', self::VER, mb_strlen($this->username, 'ASCII'));
     $login_string .= $this->username;
     $login_string .= pack('C', mb_strlen($this->password, 'ASCII'));
     $login_string .= $this->password;
     $client->send($login_string);
     $response = unpack('Cver/Cstatus', $client->recv());
     if (!isset($response['ver'], $response['status'])) {
         throw new Exception('PlainAuth: unable to parse response');
     }
     if ($response['ver'] !== self::VER) {
         throw new Exception(sprintf('PlainAuth: version mismatch (server: %d / client: %d)', $response['ver'], self::VER));
     }
     if ($response['status'] !== self::STATUS_SUCCESS) {
         throw new Exception('PlainAuth: unsuccessful login');
     }
     return true;
 }