Ciao,
non so quanto ti possa essere utile
(è di un mio vecchio script) ma meglio che niente 
Codice PHP:
class AuthXml{
private $doc= null;
private $fileName= '';
public function __construct($fileName) {
if(!file_exists($fileName)){
throw new FileException('XML file ['.$fileName.'] not found in ['.__CLASS__.']');
}
$this->fileName= $fileName;
$this->doc= new DOMDocument();
}
public function load() {
if(!$this->doc->load($this->fileName)) {
throw new FileException('Error loading file ['.$this->fileName.'] in class ['.__CLASS__.']');
}
}
public function save() {
if(!$this->doc->save($this->fileName)){
throw new FileException('Error saving file ['.$this->fileName.'] in class ['.__CLASS__.']');
}
}
public function select($item,$value){
$xp= new domxpath($this->doc);
$query= "/users/user[{$item}/text()='{$value}']";
$user= $xp->query($query);
unset($xp);
return (bool)count($user->item(0));
}
public function update($username,$password,$uid){
$xp= new domxpath($this->doc);
$query= "/users/user[password/text()='{$password}']";
$user= $xp->query($query);
unset($xp);
if(is_null($user->item(0))) {
throw new InvalidArgException('Error selecting item ['.$id.'] in ['.__CLASS__.']');
}
$item= $this->doc->createElement("user");
$data= array('username'=>$username,'password'=>$password,'uid'=>$uid);
foreach($data as $key => $value) {
$nodespace = $this->doc->createElement($key);
$nodetext = $this->doc->createTextNode($value);
$nodespace->appendChild($nodetext);
$item->appendChild($nodespace);
}
$oldnode= $user->item(0);
$newnode= $this->doc->importNode($item, true);
$oldnode->parentNode->replaceChild($newnode, $oldnode);
$this->save();
}
final public function __destruct(){
unset($this->doc);
unset($this->fileName);
}
}
class Auth{
const INVALID_LOGIN = 'Invalid Login';
private $xml= null;
public function __construct(AuthXml $xml){
$this->xml= $xml;
$this->xml->load();
}
public function startAuth($username,$password){
$this->logOut();
$username=$this->isValidString($username)?$username:'';
$password=$this->isValidString($password)?$password:'';
if($this->xml->select("username",$username)&&$this->xml->select("password",md5($password))){
$this->setAuthed($username,$password);
}
else{
Session::setSession('failedLogin',self::INVALID_LOGIN);
}
}
private function setAuthed($username,$password){
$this->generateUid(time());
$this->xml->update($username,md5($password),$this->uid);
Session::deleteSession('uip');
Session::deleteSession('uid');
Session::setSession('uip',md5($_SERVER['REMOTE_ADDR']));
Session::setSession('uid',$this->uid);
}
public function checkAuth(){
$auth = false;
$uid=isset($_SESSION['uid'])?$_SESSION['uid']:'';
if($this->isValidUid($uid)){
if($this->xml->select("uid",$_SESSION['uid']) && ($_SESSION['uip']===md5($_SERVER['REMOTE_ADDR']))){
$auth= true;
}
}
return $auth;
}
public function logOut(){
Session::deleteSession('failedLogin');
Session::deleteSession('uip');
Session::deleteSession('uid');
}
private function generateUid($time){
$this->uid= md5($time.rand(substr($time,-4),substr($time,-10)));
}
private function isValidUid($uid){
$isValid= true;
$isValid= preg_match('/^[a-z0-9]{32}$/',$uid);
settype($isValid,"bool");
return $isValid;
}
private function isValidString($string){
$isValid= TRUE;
$isValid= preg_match('/^[A-Za-z0-9\-_]{2,16}$/',$string);
settype($isValid,"bool");
return $isValid;
}
final public function __destruct(){
unset($this->xml);
}
}
il file xml
Codice PHP:
<?xml version="1.0" encoding="UTF-8"?>
<users>
<user><username>whisher</username><password>646ae72b89eb812677ea06b31b12a86e</password><uid>e4ccb10319f39c21743c053a3ed34db7</uid></user>
</users>