Advertisement
Guest User

Untitled

a guest
Sep 12th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.92 KB | None | 0 0
  1. //////////////RANDOM FUNCTIONS
  2.  
  3. function Random8() {
  4.                     $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
  5.                     $Rnd8 = array();
  6.                     $alphaLength = strlen($alphabet) - 1;
  7.                     for ($ix = 0; $ix < 8; $ix++) {
  8.                                                        $nx = rand(0, $alphaLength);
  9.                                                        $Rnd8[] = $alphabet[$nx];
  10.                                                    }
  11.                     return implode($Rnd8);
  12.                     }
  13.                                          
  14.                          
  15. function Random12() {
  16.                     $al = "0123456789";
  17.                     $Rnd12 = array();
  18.                     $alLength = strlen($al) - 1;
  19.                     for ($ixy = 0; $ixy < 12; $ixy++) {
  20.                                                        $nxy = rand(0, $alLength);
  21.                                                        $Rnd12[] = $al[$nxy];
  22.                                                    }
  23.                     return implode($Rnd12);
  24.                           }
  25.  
  26.  
  27. /////////////////////LOGIN.php
  28.  
  29. <div class="loginmodul">
  30. <?php if ($_SESSION['chiave'] <> 'put_a_complex-string_here'){ ?>
  31.         <form action="Login/newelaborate.php" method="post">
  32.               <br>
  33.               <p>EMail</p>
  34.               <input type="text" name="username">
  35.               <p>Password</p>
  36.               <input type="password" name="password"><br>
  37.               <input type="text" name="refresherX" value="1" style="display:none;">
  38.               <input type="submit" name="sendcredentials" value="Login" id="logmeinn">
  39.               <br>
  40.         </form>
  41.         <p>Forgot Password?</p>
  42.         <a href="Login/recoverpass.php">Recover Password!</a>
  43.         <p>Dont you have an account?</p>
  44.         <a href="Login/newaccount.php">Register!</a>
  45.  
  46. <?php
  47.                                              }
  48. if ($_SESSION['chiave'] == 'put_a_complex-string_here'){
  49.                                               echo '<a href="Profile.php" id="myprofile">
  50.                                              Entra nel tuo profilo</a>';
  51.                                               echo '<br> <a href="esci.php?log_off=sloggami"
  52.                                              id="exit_a">Esci</a>';
  53.                                               }
  54. ?>        
  55. </div>
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62. /////////////////////// newelaborate.php
  63.  
  64. <?php
  65. session_start();
  66. include 'myparam'; //here you can find all connection data
  67. $conn = mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
  68. if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); }
  69.  
  70.  
  71. if(is_null($_SESSION['chiave'])){
  72. if (isset($_POST['sendcredentials']) AND isset($_POST['username']) AND isset($_POST['password']))
  73.                                                                                                   {
  74. $username = $_POST['username'];
  75. $password = $_POST['password'];
  76. $username = filter_var($username, FILTER_SANITIZE_STRING);
  77. $password = filter_var($password, FILTER_SANITIZE_STRING);
  78. if ($username<>'' AND $password<>'')
  79.                                    {
  80.                                     $username = $conn->real_escape_string($username);
  81.                                     $sqlX = "SELECT identifier,user,pass,myid FROM allusers WHERE user=? LIMIT 1";
  82.                                     $stmt = $conn->prepare($sqlX);
  83.                                     $stmt->bind_param("s",$username);
  84.                                     $stmt->execute();
  85.                                     if(mysqli_errno($conn)>0) {
  86.                                                                printf("Connect failed:", mysqli_connect_error());
  87.                                                                exit();
  88.                                                                }              
  89.                                     else
  90.                                         {
  91.                                          $stmt->bind_result($checker, $user2, $password2);
  92.                                          while ($stmt->fetch()) {
  93.                                                                 $identifier = $checker;
  94.                                                                 $userX = $user2;
  95.                                                                 $PassX = $password2;    
  96.                                                                 }
  97.                                         if(is_null($userX)){echo'WRONG username and/or password';}
  98.                                         else {
  99.                                               if(password_verify($password,$PassX))
  100.                                                                                   {
  101.                                                                                    $_SESSION['chiave'] = 'put_a_complex-string_here';
  102.                                                                                    header('Location:LOGIN.php');
  103.                                                                                    exit;
  104.                                                                                   }
  105.                                               else{echo 'WRONG Password';}
  106.                                              }
  107.                                         }  
  108.                                     }
  109. else {echo 'Insert Password and Username';}                                  
  110.                                                                                                     }
  111. else{echo 'NO DATA INSERTED';}  
  112.                               }//controllo sessione
  113. if ( ($_SESSION['chiave']) AND  (!isset($_POST['sendcredentials'])) )
  114. {
  115. header('Location:LOGIN.php');
  116. exit;
  117. }
  118. ?>  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126. ////////////////////////////////////////////////////////////////////// newaccount.php
  127.  
  128. <form action="newaccount.php" method="post" class="newAC">
  129. <p>Nickname</p>
  130. <input type="text" name="nickname">
  131. <p>EMail</p>
  132. <input type="text" name="user">
  133. <p>Password</p>
  134. <input type="password" name="pass"><br>
  135. <p>Accetti l'informativa privacy?</p>
  136. <a href="<?php echo $menuimg_path[9]; ?>">Privacy Policies</a>
  137. <input type="checkbox" id="p_ac" name="privacy_acept" value="normativa_si" onchange="paccepted();">
  138. <input type="submit" name="new_acc" id="sub_newacc" value="Nuovo Account">
  139. </form>
  140.  
  141.  
  142.  
  143. <?php
  144. session_start();
  145. /*
  146. include 'myparam'; //here you can find all connection data
  147. $conn = mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
  148. if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); }
  149. $nicks= filter_var($_POST ['nickname'], FILTER_SANITIZE_EMAIL);
  150. $username2= filter_var($_POST ['user'], FILTER_SANITIZE_EMAIL);
  151. $password2 = filter_var($_POST ['pass'], FILTER_SANITIZE_STRING);
  152. $passHASH = password_hash($password2, PASSWORD_BCRYPT);
  153.  
  154. // THIS PART check ALL users's IDENTIFIER to assing a random UNIQUE identifier
  155.  
  156. $prst = $conn->prepare("SELECT identifier FROM allusers");
  157. $prst->execute();
  158. $prst->bind_result($iiden);
  159. while($prst->fetch()){$identifierlist [] = $iiden;}
  160. $ident = Random8(); //this is a function to generate a random 8 characters word
  161. $idtcheck = 0;
  162. do {
  163.     if(in_array($ident, $identifierlist)){
  164.                                           $idtcheck  = 1;
  165.                                           $ident = Random8();
  166.                                           }
  167.     if(!(in_array($ident, $identifierlist))){
  168.                                               $idtcheck  = 0;
  169.                                               }                                                        
  170.    }
  171. while   ($idtcheck!=0);
  172.  
  173. $prst = $conn->prepare("SELECT myid FROM allusers");
  174. $prst->execute();
  175. $prst->bind_result($myid);
  176. while($prst->fetch()){$mydlist [] = $myid;}
  177. $mid0 = Random12();
  178. $myidCHECK = 0;
  179.                         do {
  180.                                    for ($zy=0;$zy<count($mydlist);$zy++){
  181.                                  
  182.                                    if($mydlist[$zy] == $mid0){
  183.                                                                   $myidCHECK  = $myidCHECK +1;
  184.                                                                   $mid0 = Random12();
  185.                                                                   }
  186.                                    if($mydlist[$zy] <> $mid0){
  187.                                                                   $myidCHECK  = $myidCHECK +0;
  188.                                                                   }
  189.                                                                               }
  190.                             }
  191.                              while   ($myidCHECK !=0);
  192.  
  193.  
  194.  
  195. $prst = $conn->prepare("SELECT user FROM allusers");
  196. $prst->execute();
  197. $prst->bind_result($user);
  198. while($prst->fetch()){$userlist [] = $user;}
  199. $AEX = 0;
  200. for ($z=0;$z<count($userlist);$z++){
  201.                                    if($userlist[$z] == $username2){$AEX = $AEX+1;}
  202.                                    if($userlist[$z] <> $username2){$AEX = $AEX+0;}
  203.                                    }
  204.  
  205.                                    
  206. if (isset($_POST['new_acc'])) {
  207.  
  208. if ($AEX==0){
  209. $innsert = "INSERT INTO allusers ( user, pass, identifier, myid, Nickname ) VALUES ( ?, ?, ?, ?, ?)";
  210. $pstm = $conn->prepare($innsert);
  211. $pstm->bind_param("sssss", $username2, $passHASH, $ident, $mid0, $nicks);
  212. $pstm->execute();
  213. echo '<p id="accC">Account Creato</p>';
  214. $tablename = "mytable".$identifier; //here you should buil a unique name table for each user maybe using identifier or myid SINCE THEY ARE UNIQUE
  215.  
  216. $createSMS = "CREATE TABLE $tablename (
  217.                                        here you must put ALL fields you need for the users
  218.                                        
  219.                                        )";
  220. $pstm2 = $conn->prepare($createSMS);
  221. $pstm2->execute();
  222.            }
  223. if ($AEX>=1){echo '<p id="accC">email già in uso</p>'; }    
  224.  
  225.                              }//isset
  226.                              
  227. */                          
  228. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement