- case "auth":
- // provjeravamo autentifikaciju korisnika
- if (sizeof($aCommand) != 4){
- $this->writeLog("[exAuth] invalid auth command, data missing");
- fwrite(STDOUT, pack("nn", 2, 0));
- } else {
- // ovdje provjeri prijavu
- $sUser = str_replace(array("%20", "(a)"), array(" ", "@"), $aCommand[1]);
- $this->writeDebugLog("[debug] doing auth for ". $sUser);
- //$sQuery = "SELECT `uid`, `password` FROM `user` WHERE `password`='".hash('whirlpool',$aCommand[3])."' AND `nickname`='". $db->escape($sUser) ."'";
- $sQuery = "SELECT `uid`, `password` FROM `user` WHERE `nickname`='". $db->escape($sUser) ."'";
- $this->writeDebugLog("[debug] using query ". $sQuery);
- if ($oResult = q($sQuery)){
- $uid = $oResult[0]["uid"];
- $Error = ($oResult[0]["password"] != hash('whirlpool',$aCommand[3]));
-/*
- if ($oResult[0]["password"] == hash('whirlpool',$aCommand[3])) {
- // korisnik OK
- $this->writeLog("[exAuth] authentificated user ". $sUser ."@". $aCommand[2]);
- fwrite(STDOUT, pack("nn", 2, 1));
- } else {
- // korisnik nije OK
- $this->writeLog("[exAuth] authentification failed for user ". $sUser ."@". $aCommand[2]);
- fwrite(STDOUT, pack("nn", 2, 0));
- }
- $oResult->close();
-*/
- } else {
- $this->writeLog("[MySQL] invalid query: ". $sQuery);
- $Error = true;
- $uid = -1;
- }
- if ($Error) {
- $oConfig = q("SELECT `v` FROM `pconfig` WHERE `uid`=%d AND `cat` = 'xmpp' AND `k`='password' LIMIT 1;", intval($uid));
- $this->writeLog("[exAuth] got password ".$oConfig[0]["v"]);
- $Error = ($aCommand[3] != $oConfig[0]["v"]);
- }
-
- if ($Error) {
- $this->writeLog("[exAuth] authentification failed for user ". $sUser ."@". $aCommand[2]);
- fwrite(STDOUT, pack("nn", 2, 0));
- } else {
- $this->writeLog("[exAuth] authentificated user ". $sUser ."@". $aCommand[2]);
- fwrite(STDOUT, pack("nn", 2, 1));
- }
- }