password == sha1(md5($password)); } public function setPassword($oldpassword, $password1, $password2) { if($this->checkPassword($oldpassword) == false) { // Doublecheck the validity of the user. echo "
Current password is incorrect!
\n"; return 1; } if($password1 != $password2) { // Check if passwords match. echo "Passwords do not match!
\n"; return 1; } echo "Password updated successfully!
\n"; $this->password = sha1(md5($password1)); return 0; } public function checkModule($module) { if($this->modules == "*") return true; if($this->modules == "") return false; $modulelist = explode(" ", $this->modules); return in_array($module, $modulelist); return true; } public function User($userid, $password, $modules) { $this->userid = $userid; $this->password = $password; $this->modules = $modules; } } class Users { private $file; private $users = array(); public function add($user) { $key = $user->userid; $this->users[$key] = $user; } public function delete($user) { unset($this->users[$user]); } public function write() { $fp = fopen($this->file, "w"); fwrite($fp, "\n"); fwrite($fp, "ERROR: User! ".$userid." does not exist!
\n"; return false; } } else { echo "ERROR: You cannot delete the admin user!
\n"; return false; } return true; } public function findUser($userid) { $user = $this->users[$userid]; return $user; } public function useridList() { $useridlist = array(); foreach($this->users as $user) { array_push($useridlist, $user->userid); } return $useridlist; } private function read() { $dom = new DomDocument; $dom->preserveWhiteSpace = FALSE; $dom->load($this->file); $params = $dom->getElementsByTagName('user'); foreach ($params as $param) { $user = new User($param->getAttribute('userid'), $param->getAttribute('password'), $param->getAttribute('modules')); $this->add($user); } } public function Users($file) { $this->file = $file; $this->read(); } } ?>