Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. <?php
  2.  
  3. require_once('dbconfig.php');
  4.  
  5. class USER
  6. {
  7.  
  8. private $conn;
  9.  
  10. public function __construct()
  11. {
  12. $database = new Database();
  13. $db = $database->dbConnection();
  14. $this->conn = $db;
  15. }
  16.  
  17. public function runQuery($sql)
  18. {
  19. $stmt = $this->conn->prepare($sql);
  20. return $stmt;
  21. }
  22.  
  23. public function register($uname,$umail,$upass)
  24. {
  25. try
  26. {
  27. $new_password = password_hash($upass, PASSWORD_BCRYPT);
  28. $hash = '$2a$10$1ramrxxfQoH0Pwn8UUKf1.4te3vg/H3z4TgpZyncYSdyTGLgBWosy';
  29.  
  30. if (password_verify('meinpasswort', $hash)) {
  31. echo 'Valides Passwort!';
  32. } else {
  33. echo 'Invalides Passwort.';
  34. }
  35. $stmt = $this->conn->prepare("INSERT INTO users(user_name,user_email,user_pass)
  36. VALUES(:uname, :umail, :upass)");
  37.  
  38. $stmt->bindparam(":uname", $uname);
  39. $stmt->bindparam(":umail", $umail);
  40. $stmt->bindparam(":upass", $new_password);
  41.  
  42. $stmt->execute();
  43.  
  44. return $stmt;
  45. }
  46. catch(PDOException $e)
  47. {
  48. echo $e->getMessage();
  49. }
  50. }
  51.  
  52.  
  53. public function doLogin($uname,$umail,$upass)
  54. {
  55. try
  56. {
  57. $stmt = $this->conn->prepare("SELECT user_id, user_name, user_email, user_pass FROM users WHERE user_name=:uname OR user_email=:umail ");
  58. $stmt->execute(array(':uname'=>$uname, ':umail'=>$umail));
  59. $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
  60. if($stmt->rowCount() == 1)
  61. {
  62. if(password_verify($upass, $userRow['user_pass']))
  63. {
  64. $_SESSION['user_session'] = $userRow['user_id'];
  65. return true;
  66. }
  67. else
  68. {
  69. return false;
  70. }
  71. }
  72. }
  73. catch(PDOException $e)
  74. {
  75. echo $e->getMessage();
  76. }
  77. }
  78.  
  79. public function is_loggedin()
  80. {
  81. if(isset($_SESSION['user_session']))
  82. {
  83. return true;
  84. }
  85. }
  86.  
  87. public function redirect($url)
  88. {
  89. header("Location: $url");
  90. }
  91.  
  92. public function doLogout()
  93. {
  94. session_destroy();
  95. unset($_SESSION['user_session']);
  96. return true;
  97. }
  98. }
  99. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement