Guest User

Untitled

a guest
May 12th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.70 KB | None | 0 0
  1. <?php
  2.  
  3. require('db.php');
  4.  
  5. if($_SERVER['REQUEST_METHOD'] == 'POST') {
  6. // Throw error if a field is not filled in
  7. if(empty($_POST['username']) || empty($_POST['password']) || empty($_POST['email'])) {
  8. $err = "Vul alle velden in";
  9. $class = "fail";
  10. } else {
  11. // If everything is filled in, prepare a statement
  12. $stmt = $connect->prepare('INSERT INTO `users` (user_name, user_password, user_email, user_perms, user_created_at) VALUES (?, ?, ?, ?, ?)');
  13.  
  14. if($stmt) {
  15. // If statement gets sent correctly, create variables and add them
  16. $username = $_POST['username'];
  17.  
  18. // Hash users' password
  19. $password = password_hash($_POST['password'], PASSWORD_DEFAULT);
  20.  
  21. $email = $_POST['email'];
  22.  
  23. // Timestamp
  24. $date = date('Y-m-d H:i:s');
  25.  
  26. // Standard user permission level
  27. $perms = "Gebruiker";
  28.  
  29. // Bind parameters
  30. $stmt->bind_param('sssss', $username, $password, $email, $perms, $date);
  31.  
  32. // Check whether query ran succesfully or not
  33. if($stmt->execute()) {
  34. $err = "Het account is aangemaakt";
  35. $class = "succes";
  36. } else {
  37. $err = "Deze gebruikersnaam wordt al gebruikt";
  38. $class = "fail";
  39. }
  40. }
  41. }
  42. }
  43.  
  44. ?>
  45.  
  46. <!DOCTYPE html>
  47. <html lang="en" dir="ltr" id="form-background">
  48. <head>
  49. <meta charset="utf-8">
  50. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  51. <meta name="keywords" content="windows, windows server, linux, ubuntu, mint, install, guide, nnnext, click, tutorial, nextnextnext">
  52. <meta name="description" content="Leer veel voorkomende installaties makkelijk met nextnextnext.click!">
  53.  
  54. <title>REGISTER</title>
  55.  
  56. <link rel="stylesheet" href="./css/nnnext-main.css">
  57. <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
  58. <link rel="icon" href="./img/nnnext-favicon.ico">
  59. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  60. <link rel="stylesheet" href="./css/nnnext-backend.css">
  61.  
  62. <link rel="stylesheet" type="text/css" href="./slick/slick.css"/>
  63. <link rel="stylesheet" type="text/css" href="./slick/slick-theme.css"/>
  64. </head>
  65. <body>
  66. <div class="admin-container form-background">
  67. <div class="centered-form">
  68. <form class="login-form" method="post">
  69. <h3>REGISTER</h3>
  70. <?php
  71. if($_SERVER['REQUEST_METHOD'] == 'POST') {
  72. echo "<div class='error-handling " . $class . "'" . ">";
  73. echo "<p>" . $err . "</p>";
  74. echo "</div>";
  75. }
  76. ?>
  77. <input type="text" name="username" placeholder="Gebruikersnaam">
  78. <input type="email" name="email" placeholder="Email adres">
  79. <input type="password" name="password" placeholder="Wachtwoord">
  80. <input type="submit" name="submit" value="Account aanmaken">
  81. <p><a href="login.php">Ik heb al een account</a></p>
  82. </form>
  83. </div>
  84. </div>
  85. </body>
  86. </html>
  87.  
  88. <?php
  89. require('db.php');
  90. // If the server receives a POST request
  91. if($_SERVER['REQUEST_METHOD'] == 'POST') {
  92. if(empty($_POST['username']) || empty($_POST['password'])) {
  93. $err = "Vul beide velden in";
  94. $class = "fail";
  95. } else {
  96. // If everything has been filled in, send the query to the server
  97. $stmt = $connect->prepare('SELECT user_name, user_password, user_email, user_perms FROM `users` WHERE user_name = ?');
  98.  
  99. if($stmt) {
  100. $username = $_POST['username'];
  101. $password = $_POST['password'];
  102.  
  103. // Send parameters to the server
  104. $stmt->bind_param('s', $username);
  105.  
  106. // Run statement
  107. $stmt->execute();
  108.  
  109. // Get query result
  110. $result = $stmt->get_result();
  111.  
  112. // Fetch the query result in a row and bind to variables
  113. while($row = $result->fetch_assoc()) {
  114. $hash = $row['user_password'];
  115. $username = $row['user_name'];
  116. $email = $row['user_email'];
  117. $userPerms = $row['user_perms'];
  118. }
  119. // If there's no hash, the user does not exists
  120. if(empty($hash)) {
  121. $err = "Sorry, maar deze gebruik bestaat niet";
  122. $class = "fail";
  123. } else {
  124. // Check whether password matches hash on server
  125. if(password_verify($password, $hash)) {
  126. // Hash matches password
  127. session_start();
  128.  
  129. // Bind session variables
  130. $_SESSION['username'] = $username;
  131. $_SESSION['email'] = $email;
  132.  
  133. // Login succesful, set message and class accordingly
  134. $err = "Succesvol ingelogt. Redirecting...";
  135. $class = "succes";
  136.  
  137. // Redirect to secured page
  138. header("Location: admin.php");
  139. } else {
  140. // Password doesn't match hash, set error message accordingly
  141. $err = "Wachtwoord is incorrect";
  142. $class = "fail";
  143. }
  144. }
  145. }
  146. }
  147. }
  148.  
  149. ?>
  150.  
  151. <!DOCTYPE html>
  152. <html lang="en" dir="ltr" id="form-background">
  153. <head>
  154. <meta charset="utf-8">
  155. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  156. <meta name="keywords" content="windows, windows server, linux, ubuntu, mint, install, guide, nnnext, click, tutorial, nextnextnext">
  157. <meta name="description" content="Leer veel voorkomende installaties makkelijk met nextnextnext.click!">
  158.  
  159. <title>NNNEXT - INLOGGEN</title>
  160.  
  161. <link rel="stylesheet" href="./css/nnnext-main.css">
  162. <link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
  163. <link rel="icon" href="./img/nnnext-favicon.ico">
  164. <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  165. <link rel="stylesheet" href="./css/nnnext-backend.css">
  166.  
  167. <link rel="stylesheet" type="text/css" href="./slick/slick.css"/>
  168. <link rel="stylesheet" type="text/css" href="./slick/slick-theme.css"/>
  169. </head>
  170. <body>
  171. <div class="admin-container form-background">
  172. <div class="centered-form">
  173. <form class="login-form" method="post">
  174. <form class="login-form" method="post">
  175. <h3>Inloggen op nnnext.click</h3>
  176. <?php
  177. if($_SERVER['REQUEST_METHOD'] == 'POST') {
  178. echo "<div class='error-handling " . $class . "'" . ">";
  179. echo "<p>" . $err . "</p>";
  180. echo "</div>";
  181. }
  182. ?>
  183. <input type="text" name="username" placeholder="Gebruikersnaam">
  184. <input type="password" name="password" placeholder="Wachtwoord">
  185. <input type="submit" name="submit" value="Inloggen">
  186. <p><a href="register.php">Ik heb nog geen account</a></p>
  187. </form>
  188. </div>
  189. </div>
  190. </body>
  191. </html>
  192.  
  193. <?php
  194.  
  195. // Check whether session started or not
  196. if(!isset($_SESSION)) {
  197. session_start();
  198. }
  199.  
  200. // Check whether user is logged in or not
  201. if(!isset($_SESSION['username'])) {
  202. header("Location: login.php");
  203. exit();
  204. }
  205.  
  206. ?>
  207.  
  208. <?php
  209. // Check whether session started or not
  210. if(!isset($_SESSION)) {
  211. session_start();
  212. }
  213.  
  214. // Destroy session and redirect to login page
  215. if(session_destroy()) {
  216. header("Location: login.php");
  217. }
  218.  
  219. ?>
Add Comment
Please, Sign In to add comment