public function checkClientToken() { $token = \TBA\Header::me()->getClientToken(); //error_log("TOKEN: {$token}"); $a = new \TBA\TokenBasedAuth(); $a->setConnection(\Charon\Connection::me()->get()); try { return $a->check($token); } catch (\Exception $e) { if ($e->getCode() == 401) { $this->naoAutorizado($e->getMessage()); } } }
$sql_mysql = "\nCREATE TABLE {$db['table']} (\n\tid integer not null auto_increment primary key,\n\tusername varchar(40) not null,\n\tpasswd varchar(128) not null,\n\ttoken varchar(128),\n\ttokenval datetime,\n\tlast_login datetime\n);\n"; $sql_pgsql = "\nCREATE TABLE {$db['table']} (\n\tid serial primary key,\n\tusername varchar(40) not null,\n\tpasswd varchar(128) not null,\n\ttoken varchar(128),\n\ttokenval datetime,\n\tlast_login datetime\n);\n"; switch ($db['scheme']) { case 'pgsql': $install_table = $sql_pgsql; break; case 'mysql': default: $install_table = $sql_mysql; break; } $conn->exec($install_table); define("APP_ROOT", dirname(__DIR__)); require APP_ROOT . "/TokenBasedAuth.php"; require APP_ROOT . "/Header.php"; $app = array(); $app['tba.table_name'] = 'tba_user'; $app['tba.user_field'] = 'username'; $app['tba.pass_field'] = 'passwd'; $app['tba.token_timeout'] = '60'; $app['tba.salt'] = 'M3T45_901X'; $tba = new TBA\TokenBasedAuth($app); $tba->setConnection($conn); $sql_user = "******"; $user = '******'; $passwd = 'evaldo123'; $pwdHash = md5($app['tba.salt'] . "{$passwd}123X"); $rs = $conn->prepare($sql_user); $rs->bindParam("user", $user); $rs->bindParam("pwd", $pwdHash); $rs->execute();