Advertisement
Guest User

Untitled

a guest
Nov 26th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. <?php
  2.  
  3. class Auth {
  4.  
  5. private $options = [
  6.  
  7. "restrict_access" => "Vous ne pouvez pas accéder à cette page !"
  8.  
  9. ];
  10.  
  11. private $session;
  12.  
  13. public function __construct($session, $options = []){
  14. $this->options = array_merge($this->options, $options);
  15. $this->session = $session;
  16. }
  17.  
  18. public function register($db, $username, $password, $email, $genre, $figure, $ip){
  19. $password = password_hash($password, PASSWORD_BCRYPT);
  20. if($db->query("INSERT INTO players(username, figure, motto, credits, vip_points, activity_points, rank, gender, reg_timestamp, reg_date, last_online, online, password, email, last_ip, vip, achievement_points)
  21. VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", [
  22. $username,
  23. $figure,
  24. '- Nouveau membre -',
  25. '1500000',
  26. '0',
  27. '0',
  28. '1',
  29. $genre,
  30. time(),
  31. time(),
  32. '0',
  33. $password,
  34. $email,
  35. $ip,
  36. '0',
  37. '0'
  38. ])) {
  39. return true;
  40. } else {
  41. return false;
  42. }
  43. }
  44.  
  45. public function restrict(){
  46. if(!$this->session->getSessionValue('auth')){
  47. header('Location: ./index.php');
  48. exit();
  49. }
  50. }
  51.  
  52. public function User(){
  53. if(!$this->session->read('auth')){
  54. return false;
  55. }
  56. return $this->session->read('auth');
  57. }
  58.  
  59. public function connect($user){
  60. $this->session->write('auth', $user);
  61. }
  62.  
  63. public function Login($bdd, $username, $password)
  64. {
  65. $req = $bdd->query("SELECT * FROM players WHERE username = ? OR email = ?", [$username, $username])->fetch(PDO::FETCH_OBJ);
  66. if($req){
  67. if (password_verify($password, $req->password)) {
  68. $bdd->query('UPDATE players SET last_online = ? AND last_ip = ? WHERE id = ?', [time(), Session::IP(), $req->id]);
  69. $this->connect($req);
  70. header('Refresh:2;url=./user.php');
  71. return $req;
  72. exit();
  73. }
  74. } else {
  75. return false;
  76. }
  77. }
  78.  
  79. public function Logout(){
  80. $this->session->delete('auth');
  81. }
  82.  
  83. public function getInfo($value){
  84. return htmlentities($_SESSION['auth']->$value);
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement