PHPBuilder - User Exists?



RSS Twitter
Snippets Other

User Exists?

by: Seann Alexander
|
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 <meyowith@home.com>
//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:    $tok\n";
			$tok = strtok (":");
			echo "Password:    $tok\n";
			$tok = strtok (":");
			echo "User ID:     $tok\n";
			$tok = strtok (":");
			echo "Group ID:    $tok\n";
			$tok = strtok (":");
			echo "Group Name:  $tok\n";
			$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";
?>

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Seann Alexander

Comment:



Comment:

(Maximum characters: 1200). You have characters left.