#native_company# #native_desc#
#native_cta#

User Exists?

By Seann Alexander
on May 1, 2001

Version: .1

Type: Class

Category: Other

License: GNU General Public License

Description: Checks to see if a username exists, and if it does– it prints out the information of the user.

Web/Console version

<?php
//GPL -=- Seann Alexander <[email protected]>
//If you have not received a copy, please visit: http://www.gnu.org/copyleft/gpl.txt


class CheckUsers {
	
	VAR	$console  = "True"; //Set $console to false to enable web based version. (enabled by default)
	VAR	$fp	= "";
	VAR	$file	= "/etc/passwd";
	VAR	$rights	= "r";
	VAR	$biginfo = "";
	
	Function OpenFile($username_IN) {
		$this->fp = fopen($this->file, $this->rights);
		while (!feof($this->fp)){
			$this->BigInfo .= $this->ReadFile();
		}
		if (!($temp = stristr($this->BigInfo, $username_IN)) == "") {
		$tok = strtok ($temp,":");
			echo "Username:    $tokn";
			$tok = strtok (":");
			echo "Password:    $tokn";
			$tok = strtok (":");
			echo "User ID:     $tokn";
			$tok = strtok (":");
			echo "Group ID:    $tokn";
			$tok = strtok (":");
			echo "Group Name:  $tokn";
			$tok = strtok (":");
			echo "User Obviously Exists.n";
		} else {
			echo "False! User not Found!!n";
		}

		$tok = "";
		$temp = "";
	
		return $this->fp;
	}
	
	Function CloseFile(){
	
		fclose($this->fp);
		return 0;
	}
	
	Function ReadFile() {
		$this->ANSWER = fgets($this->fp,2);	
	        return $this->ANSWER;
	}
	
	Function UserExists($username_IN) {
		$this->OpenFile($username_IN);
		$this->Closefile();
		return $this->ANSWER;
	}
	
	Function GetUserName() {
if ($this->console == "True") {
		echo "Enter users name: ";
		$info_IN = fopen("/dev/stdin","r");
//		while (!feof($info_IN)) {
			$IN = fgets($info_IN, 1024);
//			$IN = fgetc($info_IN);
//			if ($IN == "n"){
//				echo "Your Name Is " . chop($IN) . "n";
//			}
//		}
		fclose($info_IN);
		$ret_VAL = chop($IN);


} else {
		$ret_val = $uwn;
}
		return $ret_VAL;
	}
//End Of Class

	}
	
	$CU_Class = new CheckUsers;
	
//		$CU_Class->GetUserName();
//		$CU_Class->UserExists(root);
		$CU_Class->UserExists($CU_Class->GetUserName());
		//Should be easily modifyed to check from a webpage via the following line instead:
		//$CU_Class->UserExists($uwn);
		//
		//eg: http://localhost/~page/checkusers.php?uwn=root
		//That Magic Vars has to be enabled (should be by default)	
		echo "n";
?>