Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $name = $_POST['username'];
- $password = $_POST['password'];
- $email = $_POST['email'];
- $hash = md5 (rand(0,1000));
- if(isset($name))
- {
- if (trim($name) == '' || trim($name) == ' ')
- {
- print_r('Username cannot be empty');
- }
- else
- {
- if(preg_match('/^[a-zA-Z0-9]{5,}$/', $name))
- { // for english chars + numbers only
- if( strlen($password) < 8 ) { print_r("Password too short!"); }
- elseif( !preg_match("#[0-9]+#", $password) ) { print_r("Password must include at least one number!"); }
- elseif( !preg_match("#[a-z]+#", $password) ) { print_r("Password must include at least one letter!"); }
- elseif( !preg_match("#[A-Z]+#", $password) ) { print_r("Password must include at least one CAPS!"); }
- elseif( !preg_match("#W+#", $password) ) { print_r("Password must include at least one symbol!"); }
- else
- {
- if(isset($_POST['submit']))
- {
- if(filter_var($email, FILTER_VALIDATE_EMAIL))
- {
- $subject = 'Signup | Verification'; // Give the email a subject
- $message = '
- Thanks for signing up!
- Your account has been created, you can login with the following credentials after you have activated your account by pressing the url below.
- ------------------------
- Username: '.$name.'
- Password: '.$password.'
- ------------------------
- Please click this link to activate your account:
- http://www.mywebsite.com/verify.php?email='.$email.'&hash='.$hash.'
- '; // Our message above including the link
- $headers = 'From:asdf@mywebsite.com' . "rn"; // Set from headers
- if(!isset($con))
- {
- $config = parse_ini_file('config2.ini');
- $con = mysqli_connect(`localhost`,$config["username"],$config["password"],$config["dbname"])or die ("MySQL Error: " . mysqli_connect_error());
- }
- $stmt = $con->prepare("SELECT login FROM Accounts WHERE login=?");
- $stmt->bind_param("s", $GLOBALS['name']);
- $stmt->execute();
- $stmt->bind_result($un);
- $usernamefound = 'false';
- while ($stmt->fetch())
- {
- if(isset($un))
- {
- $usernamefound = 'true';
- print_r ('Username already exists.');
- }
- }
- $stmt->close();
- if ($usernamefound == 'false')
- {
- if (filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP) || filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6))
- {
- $ip = filter_var($_SERVER['REMOTE_ADDR']);
- mail($email, $subject, $message, $headers); // Send our email
- $hashed_password = password_hash($GLOBALS['password'], PASSWORD_DEFAULT);
- $result = $con->prepare('INSERT INTO Accounts(login,password,email,lastip,hash) VALUES (?, ?, ?, ?, ?)');
- $result->bind_param("sssss", $GLOBALS['name'], $hashed_password, $GLOBALS['email'], $ip, $GLOBALS['hash']);
- $result->execute();
- $result->close();
- $con->close();
- echo "Registered: " . $ip;
- }
- else
- {
- header('Location: noIPError.html');
- die();
- }
- echo "<br/>";
- // Return Success - Valid Email
- print_r('Your account has been made, <br /> please verify it by clicking the activation link that has been send to your email.');
- }
- }
- else
- {
- // Return Error - Invalid Email
- print_r('The email you have entered is invalid, please try again.');
- }
- }
- }
- }
- else
- {
- print_r('Invalid Username: Must be alphanumeric and longer than or equal to 5 chars');
- echo "<br/>";
- print_r('No special characters or spaces allowed');
- }
- }
- }
- ?>
Add Comment
Please, Sign In to add comment