Guest User

Untitled

a guest
Oct 2nd, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. <html>
  2.  
  3. <head>
  4. <style>
  5. .bInput {
  6. border-radius: 5px;
  7. padding: 10px;
  8. margin-bottom: 10px;
  9. width: 300px;
  10. }
  11.  
  12. .pCenter {
  13. margin: 0 auto;
  14. max-width: 300px;
  15. width: 300px;
  16. }
  17. </style>
  18. </head>
  19.  
  20. <body>
  21.  
  22. <?php
  23.  
  24. error_reporting(E_ALL);
  25. ini_set('display_errors', 1);
  26.  
  27. require_once('config.php');
  28. include_once('hash.php');
  29. include_once('stationid.php');
  30.  
  31. $pass = new myHash();
  32. $stationID = new myStation_ID();
  33. $username = "";
  34. $email = "";
  35. $errors = array();
  36.  
  37. /* For testing DB connectivity
  38. if ($db->connect_error) {
  39. die("Connection failed: " . $db->connect_error);
  40. }
  41. echo "Connected successfully";
  42. */
  43.  
  44. if (isset($_POST['submit'])) {
  45.  
  46. $username = mysqli_real_escape_string($db, $_POST['username']);
  47. $email = mysqli_real_escape_string($db, $_POST['email']);
  48. $password = mysqli_real_escape_string($db, $_POST['password']);
  49.  
  50. if (empty($username)) { array_push($errors, "Username is required"); }
  51. if (empty($email)) { array_push($errors, "Email is required"); }
  52. if (empty($password)) { array_push($errors, "Password is required"); }
  53.  
  54. print_r($errors);
  55.  
  56. $user_check_query = "Select * from accounts where username='$username' OR email='$email' LIMIT 1";
  57. print_r($user_check_query);
  58. $result = mysqli_query($db, $user_check_query);
  59. $user = mysqli_fetch_assoc($result);
  60.  
  61. echo '<pre>';
  62. print_r($result);
  63. echo '</pre>';
  64.  
  65. if ($user) {
  66. if ($userp['username'] === $username) {
  67. array_push($errors, "Username already exists");
  68. }
  69.  
  70. if ($user['email'] === $email) {
  71. array_push($errors, "Email already exists");
  72. }
  73. }
  74.  
  75. if (count($errors) == 0) {
  76.  
  77. $hashedPass = mysqli_real_escape_string($db, $pass->hashPassword($password));
  78. $saltedPass = mysqli_real_escape_string($db, $pass->generateSalt());
  79. $station_id = mysqli_real_escape_string($db, $stationID->generateStationID());
  80.  
  81. $query = "insert into accounts (username, password, station_id, salt)
  82. values ('$username', '$hashedPass', '$station_id', '$saltedPass')";
  83. mysqli_query($db, $query);
  84. print_r($query);
  85. }
  86. }
  87.  
  88. ?>
  89.  
  90. <div class="pCenter">
  91. <form method="POST" action="reg.php">
  92. <input class="bInput" type="text" name="email" placeholder="Email address"><br/>
  93. <input class="bInput" type="text" name="username" placeholder="Username"><br/>
  94. <input class="bInput" type="password" name="password" placeholder="Password"><br/>
  95. <input class="bInput" type="submit" name="submit" value="submit">
  96. </form>
  97. </div>
  98. </body>
  99.  
  100. </html>
Add Comment
Please, Sign In to add comment