Advertisement
Guest User

Système de connexion avec base de donnée by @akumatereure

a guest
Nov 22nd, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.12 KB | None | 0 0
  1.  
  2. <?php
  3. <!-- Salut pour les Fainéant voici le code :) ♥♥♥ . PS:allez me follow sur Twitter @AkumaTereure -->
  4. <!-- il faut changer les endroits ou il y a ecrit A Remplacer!! par votre propre Base de donnée,Utilisateur MYSQL et Mot de passe" -->
  5. $sessionID = $GET["sessionID"];
  6. $actionget = $_GET["action"];
  7. $user = $GET["user"];
  8. $password = $GET["password"];
  9. $registerKey = $GET["registerKey"];
  10.  
  11. if (empty($sessionID)) die ("ERROR:INVALID_SESSION_ID");
  12.  
  13.  
  14. $action = new action;
  15. if ($actionget == "connect")
  16.     $response = $action->connect($user, $password);
  17. elseif ($actionget == "register")
  18. $response = $action->register($user, $password, $registerKey);
  19. else
  20. $response = "ERROR:NO_ACTION";
  21. echo rc4($sessionID, $response);
  22.  
  23. class action
  24. {
  25.     public $bdd;
  26.    
  27.     public function action()
  28.         {
  29.         try { $this->bdd = new PDO('mysql:host=localhost;dbname=A Remplacer!!', 'A Remplacer!!', 'A remplacer!!') ; }
  30.         catch (Exception $ex) { die('ERROR_BDD_CONNECTION'); }
  31.         }
  32.         public function connect ($user, $pass)
  33.        
  34.         {
  35.             if (!$this->userExist($user)) return ("ERROR:USER_NOT_FOUND");
  36.            
  37.             $data = $this->executeQuery("SELECT * FROM Users WHERE User = ?;", array($user));
  38.             if ($data['Password'] != md5($pass))
  39.                 return ("ERROR:INCORRECT_PASSWORD");
  40.             elseif ($data['Banned'] ==1)
  41.             return ("ERROR:USER_BANNED");
  42.             else
  43.                 return ("OK:") . $data['Prenium'];
  44.         }
  45.        
  46.         public function register ($user, $pass, $register)
  47.         {
  48.             $data = $this->executeQuery("SELECT * FROM Register Keys WHERE RegisterKey = ?;", array($registerKey));
  49.             if (empty($data['RegisterKey'])) return ("ERROR:INVALID_KEY");
  50.             if (!empty($data['User'])) return ("ERROR:KEY_ALREADY_USED");
  51.             if ($this->userExist ($user)) return ("ERROR:USER_ALREADY_EXIST");
  52.            
  53.             $this->executeQuery("INSERT INTO User VALUES (' ', ?, ?, '0', '0', ?);", array($user,md5($pass), getTime()));
  54.             $this->executeQuery("UPDATE RegisterKeys SET User = ? WHERE RegisterKey = ?;", array($user, $registerKey));
  55.            
  56.             return ("OK:REGISTERED");
  57.            
  58.         }
  59.        
  60.         private function userExist($user)
  61.         {
  62.             $data == $this->executeQuery("SELECT *FROM Users WHERE User = ?;", array($user));
  63.             if (empty($data['User']))
  64.                 return (false);
  65.             else return (true);
  66.            
  67.         }
  68.        
  69.        
  70.         private function executeQuery($query, $args, $fetch = true)
  71.         {
  72.             $response = $this->bdd->prepare(query);
  73.             $response->execute ($args);
  74.             if ($fetch)
  75.             {
  76.                 $data = $response->fetch();
  77.                 $response->closeCursor();
  78.                 return ($data);
  79.             }
  80.             else
  81.                 return ($response);
  82.         }
  83. }
  84.  
  85. function rc4($key, $str) {
  86. $s = array();
  87. for ($i = 0; $i < 256; $i++) {
  88. $s[$i] = $i;
  89. }
  90.  
  91. $j = 0;
  92.  
  93. for ($i = 0; $i < 256; $i++) {
  94. $j = ($j + $s[$i] + ord($key[$i % strlen($key)])) % 256;
  95. $x = $s[$i];
  96. $s[$i] = $s[$j];
  97. $s[$j] = $x;
  98. }
  99.  
  100. $i = 0;
  101. $j = 0;
  102. $res = '';
  103.  
  104. for ($y = 0; $y < strlen($str); $y++) {
  105. $i = ($i + 1) % 256;
  106. $j = ($j + $s[$i]) % 256;
  107. $x = $s[$i];
  108. $s[$i] = $s[$j];
  109. $s[$j] = $x;
  110. $res .= $str[$y] ^ chr($s[($s[$i] + $s[$j]) % 256]);
  111. }
  112.  
  113. return $res;
  114. }
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121. function getTime ()
  122. {
  123.     date_default_timezone_set('Europe/Paris');
  124.     return date("Y-m-d H:i:s");
  125. }
  126.  
  127. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement