Advertisement
Guest User

Register.php

a guest
Oct 21st, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. <?php
  2. require_once "core/init.php";
  3.  
  4. if (Input::exists()) {
  5. if (Token::check(Input::get('token'))) {
  6.  
  7. $validate = new Validate();
  8. $validation = $validate->check($_POST, array(
  9. 'username' => array(
  10. 'required' => true,
  11. 'min' => 2,
  12. 'max' => 20,
  13. 'unique' => 'users'
  14. ),
  15. 'password' => array(
  16. 'required' => true,
  17. 'min' => 6
  18. ),
  19. 'password-confirm' => array(
  20. 'required' => true,
  21. 'matches' => 'password'
  22. )
  23. ));
  24.  
  25. if ($validation->passed()) {
  26. $user = new User();
  27.  
  28. $salt = Hash::salt(32);
  29.  
  30. try {
  31. $user->create(array(
  32. 'username' => Input::get('username'),
  33. 'password' => Hash::make(Input::get('password'), $salt),
  34. 'salt' => $salt,
  35. 'joined' => date('Y-m-d H:i:s'),
  36. 'group' => 1
  37. ));
  38.  
  39. Session::flash('home', 'You have succesfully been registered and can now log in!');
  40. Redirect::to('index.php');
  41.  
  42. } catch (Exception $e) {
  43. die($e->getMessage());
  44. }
  45. } else {
  46. foreach($validation->errors() as $error) {
  47. echo $error, '<br>';
  48. }
  49. }
  50. }
  51. }
  52. ?>
  53. <form action="" method="POST">
  54. <div class="field">
  55. <label for="username">Username</label>
  56. <input type="text" name="username" id="username" value="<?php echo escape(Input::get('username')); ?>" autcomplete="off">
  57. </div>
  58. <div class="field">
  59. <label for="password">Password</label>
  60. <input type="password" name="password" id="password">
  61. </div>
  62. <div class="field">
  63. <label for="password-confirm">Confirm Password</label>
  64. <input type="password" name="password-confirm" id="password-confirm">
  65. </div>
  66. <input type="hidden" name="token" value="<?php echo Token::generate(); ?>">
  67. <input type="submit" value="Register">
  68. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement