Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once 'compat.php';
- $user = 0;
- $pass = 0;
- $mail = 0;
- if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['mail']) && !empty($_POST['user']) && !empty($_POST['pass'])) {
- function an($subject){
- if (ctype_alnum($subject)) {
- return true;
- }
- }
- if(an($_POST['user']) && strlen($_POST['user']) <= 20) {
- $user = htmlspecialchars($_POST['user']);
- } else{
- echo 'username is invalid (a-z A-Z 0-9 and less than 20 characters, please)<br>';
- }
- if(filter_var($_POST['mail'], FILTER_VALIDATE_EMAIL ) && strlen($_POST['mail']) <= 255) {
- $mail = htmlspecialchars($_POST['mail')];
- } else {
- echo 'email is invalid<br>';
- }
- if(strlen($_POST['pass']) <= 255) {
- $pass = htmlspecialchars($_POST['pass']);
- } else {
- echo 'password must be less than 255 characters<br>';
- }
- if($pass && $user && $mail) {
- $hash = md5(rand(0,1000));
- require_once('db.php');
- $sth = $db->prepare("
- INSERT INTO user_info (username, password, email, hash)
- VALUES (:username, :password, :mail, :hash)
- ");
- $sth->bindValue(":username", $user, PDO::PARAM_STR);
- $sth->bindValue(":password", password_hash($pass, PASSWORD_DEFAULT), PDO::PARAM_STR);
- $sth->bindValue(":mail", $mail, PDO::PARAM_STR);
- $sth->bindValue(":hash", $hash, PDO::PARAM_STR);
- $success = $sth->execute();
- 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>
- The last step to activating your account is clicking this link!:<br>
- http://localhost/verify.php?mail='.$mail.'&hash='.$hash.'<br>
- ';
- }
- }
- ?>
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <!--[if lt IE 9]>
- <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
- <![endif]-->
- </head>
- <body>
- <form action="" method="post">
- username: <input type="text" name="user"><br>
- password: <input type="password" name="pass"><br>
- e-mail: <input type="text" name="mail"><br>
- <input type="submit">
- </form>
- <a href="index.php">already have an account?</a>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement