Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.47 KB | None | 0 0
  1. <?php
  2. require_once "init/init.php";
  3.  
  4. $error = null;
  5. if(array_key_exists("username", $_POST)
  6. && array_key_exists("password1", $_POST)
  7. && array_key_exists("password2", $_POST))
  8. {
  9.     try
  10.     {
  11.         if(mb_strlen($_POST["username"]) < 3)
  12.             throw new Exception("Username must contain at least 3 characters.");
  13.  
  14.         if($_POST["password1"] != $_POST["password2"])
  15.             throw new Exception("Passwords don't match.");
  16.  
  17.         if(mb_strlen($_POST["password1"]) < 6)
  18.             throw new Exception("Password must contain at least 6 characters.");
  19.  
  20.         $user = $web->createUser();
  21.         $user->username = $_POST["username"];
  22.         $user->password = $_POST["password1"];
  23.  
  24.         header(sprintf("Location: %suser.php?id=%d", BASEURL, $user->id));
  25.     }
  26.     catch(Exception $e)
  27.     {
  28.         $error = $e->getMessage();
  29.     }
  30. }
  31.  
  32. include "inc/output.php";
  33. ?>
  34.  
  35. <h1>Register an account</h1>
  36.  
  37. <?if($error):?>
  38. <h2>Error: <?=html($error)?></h2>
  39. <?endif?>
  40.  
  41. <form method=post action=<?=htmlparam(REQUEST)?>>
  42.  
  43. <label for=username>Username</label>
  44. <input id=username name=username maxlength=16
  45.        value=<?=htmlparam(ifset($_POST['username']))?>>
  46.  
  47. <br>
  48.  
  49. <label for=password1>Password</label>
  50. <input id=password1 type=password name=password1>
  51.  
  52. <br>
  53.  
  54. <label for=password2>Password (repeat)</label>
  55. <input id=password2 type=password name=password2>
  56.  
  57. <br>
  58.  
  59. <button type=submit>Register</button>
  60.  
  61. </form>
  62.  
  63. <?include "inc/output.php"?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement