⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 user.class.php

📁 开源MARC数据处理
💻 PHP
字号:
<?php
/*apr-04-2004	[] pythoned	[] just a note, uploading picture is 10kb*/Class User
	{
	// taken from php.net
	//
	function _make_seed()
		{
		list($usec, $sec) = explode(' ', microtime());
		return (float) $sec + ((float) $usec * 100000);
		}
	function makePass()
		{
		define('_SYLLABELS', "*abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789");
		define('_MAKEPASS_LEN', 8);
		define('_MAKEPASS_BOX', 5000);
		// init some
		$result = '';
		mt_srand(_make_seed());
		$syllabels = _SYLLABELS;
		$len = strlen($syllabels) - 1;
		$box = "";
		// create box
		for($i = 0; $i < _MAKEPASS_BOX; $i++) 			{
			$ch = $syllabels[mt_rand(0, $len)];
			// about 20% upper case letters
			if (mt_rand(0, $len) % 5 == 1) 				{
				$ch = strtoupper($ch);
				}
			// filling up the box with random chars
			$box .= $ch;
			}
		// now collect password from box
		for($i = 0; $i < _MAKEPASS_LEN; $i++) 			{
			$result .= $box[mt_rand(0, (_MAKEPASS_BOX - 1))];
			}
		return $result;
		}
	function UserLogIn($uname, $pass, $rememberme)
		{
		list($pmldbconn) = Polerio::DBGetConn();
		$table = Polerio::DBGetTables();
		if(empty($realpass)) $realpass='';
		if (!User::comparePasswords($pass, $realpass, $uname, substr($realpass, 0, 2))) 			{
			SessionDelVar('rememberme');
			SessionDelVar('uid');
			// Set user session information (new table)
			$sessioninfocolumn = &$table['session_info_column'];
			$sessioninfotable = $table['session_info'];
			$query = "UPDATE $sessioninfotable
			SET $sessioninfocolumn[uid] = '0'
			WHERE $sessioninfocolumn[sessid] = '" . Polerio::VarPrepForStore(session_id()) . "'";
			$pmldbconn->Execute($query);
			Polerio::Redirect('index.php?_a=4&msg=3');
			} 
		if (!User::LoggedIn()) 			{
			$userscolumn = &$table['users_column'];
			$userstable = $table['users'];
			$query = "SELECT $userscolumn[uid],
					 $userscolumn[pass]
				  FROM $userstable
				  WHERE $userscolumn[uname] = '" . Polerio::VarPrepForStore($uname) ."'";
			$result = $pmldbconn->Execute($query);
			if ($result->EOF) 				{
				Polerio::Redirect('index.php?_a=4&msg=4');
				}
			list($uid, $realpass) = $result->fields;
			$result->Close();
			// Confirm that passwords match
			if (!User::comparePasswords($pass, $realpass, $uname, substr($realpass, 0, 2))) 				{
				Polerio::Redirect('index.php?_a=4&msg=3');
				}			else				{
				// Set user session information (new table)
				$sessioninfocolumn = &$table['session_info_column'];
				$sessioninfotable = $table['session_info'];
				$query = "UPDATE $sessioninfotable
					  SET $sessioninfocolumn[uid] = " . Polerio::VarPrepForStore($uid) . "
					  WHERE $sessioninfocolumn[sessid] = '" . Polerio::VarPrepForStore(session_id()) . "'";       
				$pmldbconn->Execute($query);
				// Set session variables
				SessionSetVar('uid', (int)$uid);
				if (!empty($rememberme)) 					{
					SessionSetVar('rememberme', 1);
					}
				Polerio::Redirect('index.php?_a=4&msg=1');
				// return true;
				}
			}
		}
	function comparePasswords($givenpass, $realpass, $username, $cryptSalt='')
		{		/*		 * Compare Passwords		 */		$compare2crypt = true;
		$compare2text = true;
		$md5pass = md5($givenpass);
		if ($compare2text && strcmp($md5pass, $realpass) == 0) 			{
			return $md5pass;
			}
		return false;
		}
	function UserLogOut()
		{
		/**		 * Log the user out		 * @public		 * @returns bool		 * @return true if the user successfully logged out, false otherwise		 */		list($pmldbconn) = Polerio::DBGetConn();
		$table = Polerio::DBGetTables();
		if (User::LoggedIn()) 			{
			// Reset user session information (new table)
			$sessioninfocolumn = &$table['session_info_column'];
			$sessioninfotable = $table['session_info'];
			$query = "UPDATE $sessioninfotable
				  SET $sessioninfocolumn[uid] = 0
				  WHERE $sessioninfocolumn[sessid] = '" . Polerio::VarPrepForStore(session_id()) . "'";
			$pmldbconn->Execute($query);
			SessionDelVar('rememberme');
			SessionDelVar('uid');
			Polerio::Redirect('index.php?_a=4&msg=5');
			}
		}
	function LoggedIn()
		{
		/**		 * is the user logged in?		 * @public		 * @returns bool		 * @returns true if the user is logged in, false if they are not		 */
		if(SessionGetVar('uid')) 			{
			return true;
			}		else			{
			return false;
			}
		}
	function pnUserGetVar($name, $uid=-1)
		{
		/**		 * get a user variable		 * @public		 * @author Jim McDonald		 * @param name the name of the variable		 * @param uid the user to get the variable for		 * @returns string		 * @return the value of the user variable if successful, false otherwise		 */		static $vars = array();
		if (empty($name)) 			{
			return;
			}
		if ($uid == -1) 			{
			$uid = pnSessionGetVar('uid');
			}
		if (empty($uid)) 			{
			return;
			}
		// Get this user's variables if not already obtained
		if (!isset($vars[$uid])) 			{
			$vars[$uid] = pnUserGetVars($uid);
			}
		// Return the variable
		if (isset($vars[$uid][$name])) 			{
			return $vars[$uid][$name];
			} 		else 			{
			return;
			}
		}
	} 
?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -