Guest User

Untitled

a guest
Aug 6th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. <?php require_once("includes/session.php"); ?>
  2. <?php require_once("includes/functions.php"); ?>
  3. <?php require_once("includes/connection.php"); ?>
  4. <?php confirm_logged_in(); ?>
  5. <?php
  6. include_once("includes/form_functions.php");
  7.  
  8. if (isset($_POST['submit'])) {
  9. $errors = array();
  10. $required_fields = array('username', 'password');
  11. $errors = array_merge($errors, check_required_fields($required_fields, $_POST));
  12.  
  13. $fields_with_lengths = array('username' => 30, 'password' => 30);
  14. $errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST));
  15.  
  16. $username = trim(mysql_prep($_POST['username']));
  17. $password = trim(mysql_prep($_POST['password']));
  18. $hashed_password = sha1($password);
  19.  
  20. if ( empty($errors) ) {
  21. $query = "INSERT INTO users (
  22. username, hashed_password
  23. ) VALUES (
  24. '{$username}', '{$hashed_password}'
  25. )";
  26. $result = mysql_query($query, $connection);
  27. if ($result) {
  28. $message = "The user was successfully created.";
  29. } else {
  30. $message = "The user could not be created.";
  31. $message .= "<br />" . mysql_error();
  32. }
  33. } else {
  34. if (count($errors) == 1) {
  35. $message = "There was 1 error in the form.";
  36. } else {
  37. $message = "There were " . count($errors) . " errors in the form.";
  38. }
  39. }
  40. } else {
  41. $username = "";
  42. $password = "";
  43. }
  44. ?>
  45. <?php include("includes/header.php"); ?>
  46. <table id="structure">
  47. <tr>
  48. <td id="navigation">
  49. <a href="index.php">Return to Home</a><br />
  50. <br />
  51. </td>
  52. <td id="page">
  53. <h2>Register</h2>
  54. <?php if (!empty($message)) {echo "<p class=\"message\">" . $message . "</p>";} ?>
  55. <?php if (!empty($errors)) { display_errors($errors); } ?>
  56. <form action="new_user.php" method="post">
  57. <table>
  58. <tr>
  59. <td>Username:</td>
  60. <td><input type="text" name="username" maxlength="30" value="<?php echo htmlentities($username); ?>" /></td>
  61. </tr>
  62. <tr>
  63. <td>Password:</td>
  64. <td><input type="password" name="password" maxlength="30" value="<?php echo htmlentities($password); ?>" /></td>
  65. </tr>
  66. <tr>
  67. <td colspan="2"><input type="submit" name="submit" value="Create user" /></td>
  68. </tr>
  69. </table>
  70. </form>
  71. </td>
  72. </tr>
  73. </table>
  74. <?php include("includes/footer.php"); ?>
Add Comment
Please, Sign In to add comment