Advertisement
Guest User

Untitled

a guest
Mar 17th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. <?php
  2. /**
  3. * Connect to a mysql database
  4. */
  5. class mySQL{
  6.  
  7. public $host;
  8. public $username;
  9. public $password;
  10. public $database;
  11. public $dbh;
  12.  
  13. public function connect($set_host, $set_username, $set_password, $set_database){
  14. $this->host = $set_host;
  15. $this->username = $set_username;
  16. $this->password = $set_password;
  17. $this->database = $set_database;
  18.  
  19. $this->dbh = mysql_connect($this->host, $this->username, $this->password)or die("cannot connect");
  20. mysql_select_db($this->database)or die("cannot select DB");
  21.  
  22. }
  23.  
  24. public function query($sql)
  25. {
  26. return mysql_query($sql,$this->dbh);
  27. }
  28.  
  29. public function fetch($sql)
  30. {
  31. return mysql_fetch_array($this->query($sql));
  32. }
  33.  
  34. }
  35. /**
  36. * loginsystem
  37. */
  38. class loginsystem
  39. {
  40. public $user;
  41. public $pass;
  42. public $pass2;
  43. public $email;
  44. public $crypt;
  45. public $conn;
  46. public $checkpass;
  47. public $userinfo;
  48.  
  49. public function login($username,$password)
  50. {
  51. $this->user = $username;
  52. $this->pass = $password;
  53.  
  54. $db = new mySQL();
  55. $this->conn = $db->connect('localhost','root','','oop');
  56. $this->userinfo = $db->fetch("SELECT * FROM users WHERE username = '$this->user'");
  57. if(!empty($this->user) && !empty($this->pass)){
  58. $this->checkpass = password_verify($this->pass,$this->userinfo['password']);
  59. if($this->checkpass) {
  60. $_SESSION['id'] = $this->userinfo['id'];
  61. //header('location:user.php');
  62. echo "succes";
  63. }else{
  64. echo "Wrong password or username";
  65. }
  66. } else {
  67. echo "fill in the form";
  68. }
  69. }
  70. function loginform()
  71. {
  72. echo " <form action='' method='post'>
  73. Username:
  74. <input type='text' name='user' placeholder='Username'>
  75. Password:
  76. <input type='password' name='pass' placeholder='Password'>
  77. <input type='submit' value='Login!' name='send'>
  78. </form>";
  79. }
  80. public function register($username,$password,$password2,$email)
  81. {
  82. $db = new mySQL();
  83. $this->user = $username;
  84. $this->pass = $password;
  85. $this->pass2 = $password2;
  86. $this->email = $email;
  87. $this->conn = $db->connect('localhost','root','','oop');
  88. if($this->pass == $this->pass2){
  89. $this->crypt = password_hash($this->pass, PASSWORD_DEFAULT);
  90. $db->query("INSERT INTO users VALUES('NULL','$this->user','$this->crypt','$this->email');");
  91. echo "Succesfull";
  92. } else {
  93. echo "Passwords are not the same";
  94. }
  95. }
  96.  
  97. public function registerform()
  98. {
  99. echo ' <form action="" method="post">
  100. Username:
  101. <input type="text" name="user" placeholder="Username">
  102. Password:
  103. <input type="password" name="pass" placeholder="Password">
  104. Confirm Password:
  105. <input type="password" name="pass2" placeholder="Confirm Password">
  106. E-Mail:
  107. <input type="text" name="email" placeholder="E-Mail">
  108. by registering you agree to our TOS wich can be found <a href="tos.html">here</a>
  109. <input type="submit" value="Register!" name="send">
  110. </form>';
  111. }
  112. }
  113.  
  114.  
  115. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement