1. Список говнокодов пользователя makssof

    Всего: 1

  2. PHP / Говнокод #15477

    +154

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    class Key{
    	private $chars = array('1'=>'a','2'=>'b','3'=>'c','4'=>'d','5'=>'e','6'=>'f','7'=>'g','8'=>'h','9'=>'i');
    	private $invChars = array('9'=>'a','8'=>'b','7'=>'c','6'=>'d','5'=>'e','4'=>'f','3'=>'g','2'=>'h','1'=>'i');
    	private $key = "";
    	private $numbers = array();
    
    	public function createKey(){
    		for($a=0;$a<4;$a++){
    			$this->numbers[0] = rand(1, 9);
    			$this->numbers[1] = rand(1, 9);
    			$this->key .= $this->numbers[0].$this->invChars[$this->numbers[1]].$this->numbers[1].$this->chars[$this->numbers[0]]."-";
    		}
    		return substr_replace($this->key, '', 19, 1);
    	}
    
    	public function checkKey($key){
    		if(preg_match("/^([1-9][a-iA-I][1-9][a-iA-I][\-][1-9][a-iA-I][1-9][a-iA-I][\-][1-9][a-iA-I][1-9][a-iA-I][\-][1-9][a-iA-I][1-9][a-iA-I])$/", $key)){
    			$key = str_replace('-', '', $key);
    			if($this->chars[$key[0]] == $key[3] && $this->invChars[$key[2]] == $key[1]){
    				if($this->chars[$key[4]] == $key[7] && $this->invChars[$key[6]] == $key[5]){
    					if($this->chars[$key[8]] == $key[11] && $this->invChars[$key[10]] == $key[9]){
    						if($this->chars[$key[12]] == $key[15] && $this->invChars[$key[14]] == $key[13]){
    							return true;
    						}
    						else{
    							return false;
    						}
    					}
    					else{
    						return false;
    					}
    				}
    				else{
    					return false;
    				}
    			}
    			else{
    				return false;
    			}
    		}
    		else{
    			return false;
    		}
    	}
    }

    Особенно регулярка...

    makssof, 14 Марта 2014

    Комментарии (2)