<?php
/**
 * auth_local.php - Local database authentication class
 *
 * @author $Author: dtong $
 * @version $Id: auth_local.php,v 1.7 2011/05/18 03:50:08 dtong Exp $
 * @copyright Copyright (c) 2009, Tiller Software Co., Ltd.
*/

require_once('auth_base.php');

class auth_local extends auth_base {

   function authenticate($username, $password, $dbpassword) {
   	if ( is_null($this->config) ) {
   	  return FALSE;
   	}
   	if ( $dbpassword ) {
	   	//This should never happen, but if some local user has this password then
	   	//refuse the login
	   	if ( $dbpassword == $this->config->item('cms_local_nologin_password') ) {
	   	  return FALSE;
	   	}
	      $modpass = $password . $this->config->item('cms_password_key');
	      $md5pass = md5($modpass);
	   	if ( $md5pass == $dbpassword ) {
	   	  return TRUE;
	   	}
   	}
   	else {
	   	//Magic password is special and normally turned off
	   	if ( $this->config->item('cms_magic_password') && md5($password) == $this->config->item('cms_magic_password') ) {
	   		return TRUE;
	   	}
   	}
   	return FALSE;
   }
}
?>