Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.08 KB | None | 0 0
  1. <?php
  2. Include('Connect.php');
  3. error_reporting(E_ALL);
  4. ini_set('display_errors', 1);
  5.  
  6. $main_password ""; 
  7. $message = "";
  8.  
  9. function test_input($data) {
  10.         $data = trim($data);
  11.         $data = stripslashes($data);
  12.         $data = htmlspecialchars($data);
  13.         return $data;
  14.     }
  15. function Usernamequery($connection,$username){
  16.         $arrayUsername = array();
  17.         $result =  mysqli_query($connection, "SELECT * FROM `Members_Information` WHERE username = '$username'");
  18.         if($result == true){
  19.          while($row = mysqli_fetch_array($result))
  20.         $arrayUsername = $row['Username'];
  21.         }if ($arrayUsername == $username){
  22.            
  23.         return  true;
  24.             }else{
  25.         return false;
  26.             }  
  27.     }
  28. function Emailquery($connection,$email){
  29.         $arrayemail = array();
  30.         $result =  mysqli_query($connection, "SELECT * FROM `Members_Information` WHERE email = '$email'");
  31.         if($result == true){
  32.          while($row = mysqli_fetch_array($result))
  33.         $arrayemail = $row['email'];
  34.         }if ($arrayemail == $email){
  35.            
  36.         return  true;
  37.             }else{
  38.         return false;
  39.             }  
  40.     }  
  41.    
  42.    
  43.    
  44. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  45.     if (empty($_POST["username"]) == false) {
  46.         $username = test_input($_POST["username"]);
  47.         if (empty($_POST["password1"])== false) {
  48.             $password1 = test_input($_POST["password1"]);
  49.             if (empty($_POST["password2"]) == false) {
  50.                 $password2 = test_input($_POST["password2"]);
  51.                 if (empty($_POST["email"]) == false) {
  52.                     $email = test_input($_POST["email"]);
  53.                     if (Usernamequery($connection, $username) == false){
  54.                         if (Emailquery($connection, $email) == false){
  55.                             if ($password1 == $password2){
  56.                                 $password1 = $password;
  57.                                 if (strlen($password) >= 6 && strlen($password) <= 15){
  58.                                     $pepper = "Jg"; // USED TO ADD A CONSISTENT PEPPER TO ALL PASSWORDS
  59.                                     $characters = '1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM';
  60.                                     $randomString = '';
  61.                                     $length = 8;
  62.                                     for ($i = 0; $i < $length; $i++) {
  63.                                         $randomString .= $characters[rand(0, strlen($characters) - 1)];
  64.                                     }
  65.                                     $salt = $randomString;
  66.                                      
  67.                                     // HASH PASSWORD
  68.                                     $main_password = trim($password);
  69.                                     $main_password = bin2hex(mhash(MHASH_MD5, sha1($main_password.$pepper)));
  70.                                     $main_password = $salt.$main_password;
  71.  
  72.                                     $active = 0 ;
  73.                                     $sql = $connection->prepare("INSERT INTO Members_Information(Id, Password, Username, Email, UserId, Active) VALUES (Id,?,?,?,?,?)");           
  74.                                     $sql->bind_param('sss', $main_password, $username, $email, $userId, $active);
  75.                                     $sql->execute();
  76.                                     $sql->close();
  77.                                    
  78.                                    
  79.                                 }else {$message ="Password needs to have more then 6 characters but less than 16";}
  80.                             }else {$message = "Passwords are not the same!";}
  81.                         }else { $message = "Please use a different Email!";}
  82.                     }else { $message = "Please choose a different Username!";}
  83.                 }else { $message = "Email is required!";}
  84.             }else { $message = "Password is required!";}
  85.         }else { $message = "Password is required!";}
  86.     }else { $message = "Username is required!";}
  87. } else{ $errormessage = "Data Not Found!";}
  88. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement