Index: inc/core/class.dc.auth.php
===================================================================
--- inc/core/class.dc.auth.php	(revision 2311)
+++ inc/core/class.dc.auth.php	(revision 2566)
@@ -16,5 +16,5 @@
 * @nosubgrouping
 * @brief Authentication and user credentials management
-* 
+*
 * dcAuth is a class used to handle everything related to user authentication
 * and credentials. Object is provided by dcCore $auth property.
@@ -26,10 +26,10 @@
 	/** @var connection Database connection object */
 	protected $con;
-	
+
 	/** @var string User table name */
 	protected $user_table;
 	/** @var string Perm table name */
 	protected $perm_table;
-	
+
 	/** @var string Current user ID */
 	protected $user_id;
@@ -50,14 +50,14 @@
 	/** @var integer Count of user blogs */
 	public $blog_count = null;
-	
+
 	/** @var array Permission types */
 	protected $perm_types;
-	
+
 	/** @var dcPrefs dcPrefs object */
 	public $user_prefs;
-	
+
 	/**
 	* Class constructor. Takes dcCore object as single argument.
-	* 
+	*
 	* @param dcCore	$core		dcCore object
 	*/
@@ -69,5 +69,5 @@
 		$this->user_table = $core->prefix.'user';
 		$this->perm_table = $core->prefix.'permissions';
-		
+
 		$this->perm_types = array(
 			'admin' => __('administrator'),
@@ -81,5 +81,5 @@
 		);
 	}
-	
+
 	/// @name Credentials and user permissions
 	//@{
@@ -88,5 +88,5 @@
 	* while you may need to check user without password. This method will create
 	* credentials and populate all needed object properties.
-	* 
+	*
 	* @param string	$user_id		User ID
 	* @param string	$pwd			User password
@@ -104,5 +104,5 @@
 				'FROM '.$this->con->escapeSystem($this->user_table).' '.
 				"WHERE user_id = '".$this->con->escape($user_id)."' ";
-		
+
 		try {
 			$rs = $this->con->select($strReq);
@@ -110,13 +110,13 @@
 			$err = $e->getMessage();
 			return false;
-		}		
-		
+		}
+
 		if ($rs->isEmpty()) {
 			sleep(rand(2,5));
 			return false;
 		}
-		
+
 		$rs->extend('rsExtUser');
-		
+
 		if ($pwd != '')
 		{
@@ -132,9 +132,9 @@
 			}
 		}
-		
+
 		$this->user_id = $rs->user_id;
 		$this->user_change_pwd = (boolean) $rs->user_change_pwd;
 		$this->user_admin = (boolean) $rs->user_super;
-		
+
 		$this->user_info['user_pwd'] = $rs->user_pwd;
 		$this->user_info['user_name'] = $rs->user_name;
@@ -149,12 +149,12 @@
 		$this->user_info['user_creadt'] = $rs->user_creadt;
 		$this->user_info['user_upddt'] = $rs->user_upddt;
-		
+
 		$this->user_info['user_cn'] = dcUtils::getUserCN($rs->user_id, $rs->user_name,
 		$rs->user_firstname, $rs->user_displayname);
-		
+
 		$this->user_options = array_merge($this->core->userDefaults(),$rs->options());
-		
+
 		$this->user_prefs = new dcPrefs($this->core,$this->user_id);
-		
+
 		# Get permissions on blogs
 		if ($check_blog && ($this->findUserBlog() === false)) {
@@ -163,8 +163,8 @@
 		return true;
 	}
-	
+
 	/**
 	* This method only check current user password.
-	* 
+	*
 	* @param string	$pwd			User password
 	* @return boolean
@@ -175,11 +175,11 @@
 			return $pwd == $this->user_info['user_pwd'];
 		}
-		
+
 		return false;
 	}
-	
+
 	/**
 	* This method checks if user session cookie exists
-	* 
+	*
 	* @return boolean
 	*/
@@ -188,8 +188,8 @@
 		return isset($_COOKIE[DC_SESSION_NAME]);
 	}
-	
+
 	/**
 	* This method checks user session validity.
-	* 
+	*
 	* @return boolean
 	*/
@@ -197,5 +197,5 @@
 	{
 		$this->core->session->start();
-		
+
 		# If session does not exist, logout.
 		if (!isset($_SESSION['sess_user_id'])) {
@@ -203,19 +203,19 @@
 			return false;
 		}
-		
+
 		# Check here for user and IP address
 		$this->checkUser($_SESSION['sess_user_id']);
 		$uid = $uid ? $uid : http::browserUID(DC_MASTER_KEY);
-		
+
 		$user_can_log = $this->userID() !== null && $uid == $_SESSION['sess_browser_uid'];
-		
+
 		if (!$user_can_log) {
 			$this->core->session->destroy();
 			return false;
 		}
-		
+
 		return true;
 	}
-	
+
 	/**
 	* Checks if user must change his password in order to login.
@@ -227,8 +227,8 @@
 		return $this->user_change_pwd;
 	}
-	
+
 	/**
 	* Checks if user is super admin
-	* 
+	*
 	* @return boolean
 	*/
@@ -237,10 +237,10 @@
 		return $this->user_admin;
 	}
-	
+
 	/**
 	* Checks if user has permissions given in <var>$permissions</var> for blog
 	* <var>$blog_id</var>. <var>$permissions</var> is a coma separated list of
 	* permissions.
-	* 
+	*
 	* @param string	$permissions	Permissions list
 	* @param string	$blog_id		Blog ID
@@ -252,8 +252,8 @@
 			return true;
 		}
-		
+
 		$p = explode(',',$permissions);
 		$b = $this->getPermissions($blog_id);
-		
+
 		if ($b != false)
 		{
@@ -261,5 +261,5 @@
 				return true;
 			}
-			
+
 			foreach ($p as $v)
 			{
@@ -269,11 +269,11 @@
 			}
 		}
-		
+
 		return false;
 	}
-	
+
 	/**
 	* Returns true if user is allowed to change its password.
-	* 
+	*
 	* @return	boolean
 	*/
@@ -283,5 +283,5 @@
 	}
 	//@}
-	
+
 	/// @name User code handlers
 	//@{
@@ -293,37 +293,37 @@
 		return bin2hex($code);
 	}
-	
+
 	public function checkUserCode($code)
 	{
 		$code = @pack('H*',$code);
-		
+
 		$user_id = trim(@pack('a32',substr($code,0,32)));
 		$pwd = @unpack('H40hex',substr($code,32,40));
-		
+
 		if ($user_id === false || $pwd === false) {
 			return false;
 		}
-		
+
 		$pwd = $pwd['hex'];
-		
+
 		$strReq = 'SELECT user_id, user_pwd '.
 				'FROM '.$this->user_table.' '.
 				"WHERE user_id = '".$this->con->escape($user_id)."' ";
-		
+
 		$rs = $this->con->select($strReq);
-		
+
 		if ($rs->isEmpty()) {
 			return false;
 		}
-		
+
 		if (crypt::hmac(DC_MASTER_KEY,$rs->user_pwd) != $pwd) {
 			return false;
 		}
-		
+
 		return $rs->user_id;
 	}
 	//@}
-	
-	
+
+
 	/// @name Sudo
 	//@{
@@ -331,5 +331,5 @@
 	* Calls $f function with super admin rights.
 	* Returns the function result.
-	* 
+	*
 	* @param callback	$f			Callback function
 	* @return mixed
@@ -340,8 +340,8 @@
 			throw new Exception($f.' function doest not exist');
 		}
-		
+
 		$args = func_get_args();
 		array_shift($args);
-		
+
 		if ($this->user_admin) {
 			$res = call_user_func_array($f,$args);
@@ -356,18 +356,18 @@
 			}
 		}
-		
+
 		return $res;
 	}
 	//@}
-	
+
 	/// @name User information and options
 	//@{
 	/**
 	* Returns user permissions for a blog as an array which looks like:
-	* 
+	*
 	*  - [blog_id]
 	*    - [permission] => true
 	*    - ...
-	* 
+	*
 	* @param string	$blog_id		Blog ID
 	* @return array
@@ -384,10 +384,10 @@
 				"WHERE blog_id = '".$this->con->escape($blog_id)."' ";
 			$rs = $this->con->select($strReq);
-			
+
 			$this->blogs[$blog_id] = $rs->isEmpty() ? false : array('admin' => true);
-			
+
 			return $this->blogs[$blog_id];
 		}
-		
+
 		$strReq = 'SELECT permissions '.
 				'FROM '.$this->perm_table.' '.
@@ -396,7 +396,7 @@
 				"AND (permissions LIKE '%|usage|%' OR permissions LIKE '%|admin|%' OR permissions LIKE '%|contentadmin|%') ";
 		$rs = $this->con->select($strReq);
-		
+
 		$this->blogs[$blog_id] = $rs->isEmpty() ? false : $this->parsePermissions($rs->permissions);
-		
+
 		return $this->blogs[$blog_id];
 	}
@@ -409,5 +409,5 @@
         return $this->blog_count;
     }
-	
+
 	public function findUserBlog($blog_id=null)
 	{
@@ -434,5 +434,5 @@
 						$this->con->limit(1);
 			}
-			
+
 			$rs = $this->con->select($strReq);
 			if (!$rs->isEmpty()) {
@@ -440,11 +440,11 @@
 			}
 		}
-		
+
 		return false;
 	}
-	
+
 	/**
 	* Returns current user ID
-	* 
+	*
 	* @return string
 	*/
@@ -453,8 +453,8 @@
 		return $this->user_id;
 	}
-	
+
 	/**
 	* Returns information about a user .
-	* 
+	*
 	* @param string	$n			Information name
 	* @return string
@@ -465,11 +465,11 @@
 			return $this->user_info[$n];
 		}
-		
+
 		return null;
 	}
-	
+
 	/**
 	* Returns a specific user option
-	* 
+	*
 	* @param string	$n			Option name
 	* @return string
@@ -482,8 +482,8 @@
 		return null;
 	}
-	
+
 	/**
 	* Returns all user options in an associative array.
-	* 
+	*
 	* @return array
 	*/
@@ -493,10 +493,10 @@
 	}
 	//@}
-	
+
 	/// @name Permissions
 	//@{
 	/**
 	* Returns an array with permissions parsed from the string <var>$level</var>
-	* 
+	*
 	* @param string	$level		Permissions string
 	* @return array
@@ -506,5 +506,5 @@
 		$level = preg_replace('/^\|/','',$level);
 		$level = preg_replace('/\|$/','',$level);
-		
+
 		$res = array();
 		foreach (explode('|',$level) as $v) {
@@ -513,8 +513,8 @@
 		return $res;
 	}
-	
+
 	/**
 	* Returns <var>perm_types</var> property content.
-	* 
+	*
 	* @return array
 	*/
@@ -523,8 +523,8 @@
 		return $this->perm_types;
 	}
-	
+
 	/**
 	* Adds a new permission type.
-	* 
+	*
 	* @param string	$name		Permission name
 	* @param string	$title		Permission title
@@ -535,5 +535,5 @@
 	}
 	//@}
-	
+
 	/// @name Password recovery
 	//@{
@@ -541,5 +541,5 @@
 	* Add a recover key to a specific user identified by its email and
 	* password.
-	* 
+	*
 	* @param string	$user_id		User ID
 	* @param string	$user_email	User Email
@@ -552,28 +552,28 @@
 				"WHERE user_id = '".$this->con->escape($user_id)."' ".
 				"AND user_email = '".$this->con->escape($user_email)."' ";
-		
+
 		$rs = $this->con->select($strReq);
-		
+
 		if ($rs->isEmpty()) {
 			throw new Exception(__('That user does not exist in the database.'));
 		}
-		
+
 		$key = md5(uniqid());
-		
+
 		$cur = $this->con->openCursor($this->user_table);
 		$cur->user_recover_key = $key;
-		
+
 		$cur->update("WHERE user_id = '".$this->con->escape($user_id)."'");
-		
+
 		return $key;
 	}
-	
+
 	/**
 	* Creates a new user password using recovery key. Returns an array:
-	* 
+	*
 	* - user_email
 	* - user_id
 	* - new_pass
-	* 
+	*
 	* @param string	$recover_key	Recovery key
 	* @return array
@@ -584,23 +584,23 @@
 				'FROM '.$this->user_table.' '.
 				"WHERE user_recover_key = '".$this->con->escape($recover_key)."' ";
-		
+
 		$rs = $this->con->select($strReq);
-		
+
 		if ($rs->isEmpty()) {
 			throw new Exception(__('That key does not exist in the database.'));
 		}
-		
+
 		$new_pass = crypt::createPassword();
-		
+
 		$cur = $this->con->openCursor($this->user_table);
 		$cur->user_pwd = crypt::hmac(DC_MASTER_KEY,$new_pass);
 		$cur->user_recover_key = null;
-		
+
 		$cur->update("WHERE user_recover_key = '".$this->con->escape($recover_key)."'");
-		
+
 		return array('user_email' => $rs->user_email, 'user_id' => $rs->user_id, 'new_pass' => $new_pass);
 	}
 	//@}
-	
+
 	/** @name User management callbacks
 	This 3 functions only matter if you extend this class and use
@@ -611,5 +611,5 @@
 	*/
 	//@{
-	
+
 	/**
 	* Called after core->addUser
@@ -618,5 +618,5 @@
 	*/
 	public function afterAddUser($cur) {}
-	
+
 	/**
 	* Called after core->updUser
@@ -626,5 +626,5 @@
 	*/
 	public function afterUpdUser($id,$cur) {}
-	
+
 	/**
 	* Called after core->delUser
@@ -635,3 +635,2 @@
 	//@}
 }
-?>
