Advertisement
Guest User

Thanks! :)

a guest
May 12th, 2014
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.09 KB | None | 0 0
  1. <?php
  2. include_once 'compat.php';
  3. $user = 0;
  4. $pass = 0;
  5. $mail = 0;
  6. if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['mail']) && !empty($_POST['user']) && !empty($_POST['pass'])) {
  7.     function an($subject){
  8.         if (ctype_alnum($subject)) {
  9.             return true;
  10.         }
  11.     }
  12.     if(an($_POST['user']) && strlen($_POST['user']) <= 20) {
  13.         $user = htmlspecialchars($_POST['user']);
  14.     } else{
  15.         echo 'username is invalid (a-z A-Z 0-9 and less than 20 characters, please)<br>';
  16.     }
  17.     if(filter_var($_POST['mail'], FILTER_VALIDATE_EMAIL ) && strlen($_POST['mail']) <= 255) {
  18.         $mail = htmlspecialchars($_POST['mail')];
  19.     } else {
  20.         echo 'email is invalid<br>';
  21.     }
  22.     if(strlen($_POST['pass']) <= 255) {
  23.         $pass = htmlspecialchars($_POST['pass']);
  24.     } else {
  25.         echo 'password must be less than 255 characters<br>';
  26.     }
  27.     if($pass && $user && $mail) {
  28.         $hash = md5(rand(0,1000));
  29.         require_once('db.php');
  30.         $sth = $db->prepare("
  31.                 INSERT INTO user_info (username, password, email, hash)
  32.                 VALUES (:username, :password, :mail, :hash)
  33.         ");
  34.         $sth->bindValue(":username", $user, PDO::PARAM_STR);
  35.         $sth->bindValue(":password", password_hash($pass, PASSWORD_DEFAULT), PDO::PARAM_STR);
  36.         $sth->bindValue(":mail", $mail, PDO::PARAM_STR);
  37.         $sth->bindValue(":hash", $hash, PDO::PARAM_STR);
  38.         $success = $sth->execute();
  39.         echo 'You have been successfully signed up :)! To activate your account, click the link in your e-mail account (check your spam box if you don\'t get the e-mail!)<br>
  40.         The last step to activating your account is clicking this link!:<br>
  41.         http://localhost/verify.php?mail='.$mail.'&hash='.$hash.'<br>
  42.         ';
  43.     }
  44. }
  45. ?>
  46. <!doctype html>
  47. <html lang="en">
  48. <head>
  49.     <meta charset="utf-8">
  50.     <!--[if lt IE 9]>
  51.     <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  52.     <![endif]-->
  53. </head>
  54.  
  55. <body>
  56.     <form action="" method="post">
  57.         username: <input type="text" name="user"><br>
  58.         password: <input type="password" name="pass"><br>
  59.         e-mail: <input type="text" name="mail"><br>
  60.         <input type="submit">
  61.     </form>
  62.     <a href="index.php">already have an account?</a>
  63. </body>
  64. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement