* @version 1.0.1 (July 21, 2004) * @package AutoIndex */ class User { /** * @var string Username */ public $username; /** * @var string The password, stored as a sha-1 hash of the actual password */ public $sha1_pass; /** * @var int The user's level (use the GUEST USER ADMIN constants) */ public $level; /** * @var string The user's home directory, or an empty string to use the default base_dir */ public $home_dir; /** * @param User $user The user to compare to $this * @return bool True if this user is equal to $user, based on username and password */ public function equals(User $user) { return ((strcasecmp($this -> username, $user -> username) === 0) && (strcasecmp($this -> sha1_pass, $user -> sha1_pass) === 0)); } /** * Since this is not an instance of UserLoggedIn, we know he is not * logged in. */ public function logout() { throw new ExceptionDisplay('You are not logged in.'); } /** * Here we display a login box rather than account options, since this is * not an instance of UserLoggedIn. * * @return string The HTML text of the login box */ public function login_box() { $str = ''; if (USE_LOGIN_SYSTEM) { global $words, $subdir; $str .= '
' . $words -> __get('username') . ':' . '
' . $words -> __get('password') . ':
' . '

'; } if (LEVEL_TO_UPLOAD === GUEST) { global $you; $upload_panel = new Upload($you); $str .= $upload_panel -> __toString(); } return $str; } /** * @param string $username Username * @param string $sha1_pass Password as a sha-1 hash * @param int $level User's level (use the GUEST, USER, MODERATOR, ADMIN constants) * @param string $home_dir The home directory of the user, or blank for the default */ public function __construct($username = '', $sha1_pass = '', $level = GUEST, $home_dir = '') { $level = (int)$level; if ($level < BANNED || $level > ADMIN) { throw new ExceptionDisplay('Error in user accounts file: Invalid user level (for username "' . Url::html_output($username) . '").'); } if ($sha1_pass != '' && strlen($sha1_pass) !== 40) { throw new ExceptionDisplay('Error in user accounts file: Invalid password hash (for username "' . Url::html_output($username) . '").'); } $this -> sha1_pass = $sha1_pass; $this -> username = $username; $this -> level = $level; $this -> home_dir = $home_dir; } /** * @return string This string format is how it is stored in the user_list file */ public function __toString() { return $this -> username . "\t" . $this -> sha1_pass . "\t" . $this -> level . "\t" . $this -> home_dir . "\n"; } } ?>