Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- abstract class User
- {
- protected $username;
- protected $password;
- abstract function checkLogin($username, $password);
- abstract function setLogin($username);
- abstract function setPassword($password);
- final public function login($username, $password){
- return $this->checkLogin($username,$password);
- }
- }
- class Client extends User {
- function checkLogin($username, $password)
- {
- if ($password != $this->password) return false;
- if ($username != $this->username) return false;
- return true;
- }
- function setLogin($username)
- {
- $this->username = $username;
- }
- function setPassword($password)
- {
- if ( strlen($password) < 8 ) return false;
- $this->password = $password;
- }
- function getPassword(){
- return $this->password;
- }
- public function getUsername()
- {
- return $this->username;
- }
- }
- class Admin extends User {
- private $ip;
- function checkLogin($username, $password)
- {
- $this->ip = "192.168.33.22";
- if ($password != $this->password) return false;
- if ($username != $this->username) return false;
- return true;
- }
- function setLogin($username)
- {
- $this->username = $username;
- }
- function setPassword($password)
- {
- if ( strlen($password) < 9 ) return false;
- $this->password = $password;
- }
- }
- class UserSet implements Iterator {
- private $users = array();
- private $index = 0;
- public function add($user){
- $this->users[] = $user;
- }
- public function current()
- {
- return $this->users[$this->index];
- }
- public function next()
- {
- $this->index++;
- }
- public function key()
- {
- }
- public function valid()
- {
- if ($this->index == count($this->users)) return false;
- return true;
- }
- public function rewind()
- {
- $this->index=0;
- }
- public function checkLogin($password){
- foreach ($this as $user){
- if ($password == $user->getPassword()) echo $user->getUserName()."\n";
- }
- }
- }
- $admin = new Admin();
- $admin->setLogin("admin");
- $admin->setPassword("testowiecsda");
- if ($admin->login("admin","testowiecs")){
- echo "brawo";
- }
- $userSet = new UserSet();
- $c1 = new Client();
- $c1->setLogin("marek");
- $c1->setPassword("zegarek");
- $c2 = new Client();
- $c2->setLogin("arek");
- $c2->setPassword("figlarek");
- $c3 = new Client();
- $c3->setLogin("test");
- $c3->setPassword("testowski");
- $userSet->add($c1);
- $userSet->add($c2);
- $userSet->add($c3);
- $userSet->checkLogin("figlarek");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement