Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- abstract class user {
- private $fails = 0;
- protected $password;
- protected $username;
- abstract public function setPassword($password);
- abstract public function setUsername($username);
- abstract protected function checkLogin($username, $password);
- final public function login($username, $password){
- if($this->fails < 3){
- if(!$this->checkLogin($username, $password)){
- $this->fails++;
- } else {
- $this->fails = 0;
- echo "Acc logged in\n";
- }
- } else {
- echo "Acc blocked\n";
- }
- }
- }
- class admin extends user {
- public function setPassword($password){
- if(strlen($password)>=10){
- echo "Pass: ok\n";
- } else {
- echo "Pass: not ok\n";
- }
- $this->password = $password;
- }
- public function setUsername($username){$this->username = $username;}
- protected function checkLogin($username, $password){
- return ($this->username == $username && $this->password == $password);
- }
- }
- class client extends user {
- public function setPassword($password){
- if(strlen($password)>=8){
- echo "Pass: ok\n";
- } else {
- echo "Pass: not ok\n";
- }
- $this->password = $password;
- }
- public function setUsername($username){$this->username = $username;}
- public function getUsername(){return $this->username;}
- public function getPassword(){return $this->password;}
- protected function checkLogin($username, $password){
- return ($this->username == $username && $this->password == $password);
- }
- }
- class UserSet implements Iterator{
- private $position = 0;
- private $userSet;
- public function __construct() {
- $this->position = 0;
- }
- public function rewind() {
- $this->position = 0;
- }
- public function current() {
- return $this->userSet[$this->position];
- }
- public function key() {
- return $this->position;
- }
- public function next() {
- ++$this->position;
- }
- public function valid() {
- return isset($this->userSet[$this->position]);
- }
- public function add(Client $obj){
- $this->userSet[] = $obj;
- }
- }
- function checkLogin($password, UserSet $set){
- foreach($set as $obj){
- if($obj->getPassword() == $password){
- echo $obj->getUsername() . "\n";
- }
- }
- }
- $obj1 = new client();
- $obj1->setUsername('Admin');
- $obj1->setPassword('1234');
- $obj2 = new client();
- $obj2->setUsername('Client1');
- $obj2->setPassword('1234');
- $obj3 = new client();
- $obj3->setUsername('Client2');
- $obj3->setPassword('12345');
- $obj4 = new client();
- $obj4->setUsername('Client3');
- $obj4->setPassword('12345');
- $objSet = new UserSet();
- $objSet->add($obj1);
- $objSet->add($obj2);
- $objSet->add($obj3);
- $objSet->add($obj4);
- checkLogin('12345', $objSet);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement