Guest User

Untitled

a guest
Aug 8th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. // connect_mysql.php
  2. <?php
  3.  
  4. define("DB_HOST", "localhost");
  5. define("DB_USER", "user");
  6. define("DB_PASS", "pass");
  7. define("DB_DB", "_notify");
  8.  
  9. $dbc = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_DB);
  10.  
  11. if (!$dbc) {
  12. die('Cannot connect to database: ' . $dbc->error);
  13. }
  14. ?>
  15.  
  16. // index.php
  17. <?php
  18.  
  19. include('./connect_mysql.php');
  20.  
  21. class Login {
  22.  
  23. public $user;
  24. private $pass;
  25. private $_authCode;
  26.  
  27. public function __construct($user, $password) {
  28. $this->user = $user;
  29. $this->pass = $password;
  30. $this->_authCode = -1;
  31. }
  32.  
  33. public function authCode() {
  34. return $this->_authCode;
  35. }
  36. public function authenticate() {
  37. $q = "SELECT username, password FROM users";
  38. $r = $dbc->query($q);
  39.  
  40. while ($check = $r->fetch_object()) {
  41. if ($user == $check->username) {
  42. if (trim(md5('$password')) == $check->password) {
  43. $this->_authCode = 1;
  44. break;
  45. }
  46. else {
  47. $this->_authCode = 0;
  48. break;
  49. }
  50. }
  51. }
  52. }
  53. }
  54. ?>
Add Comment
Please, Sign In to add comment