2017-06-21 1 views
0

Ich entwickle ein Plug-In für Joomla! aber angesichts der Komplexität des Skripts habe ich es aus der Kernstruktur heraus entwickelt.Anmeldeinformation aus Joomla bestätigen! Kernstruktur

Jetzt ist das einzige Problem, das ich habe, Benutzer nur einmal als Administratoren einloggen und meinem Plug-in-Ordner folgen, der verlegt wird, nur wenn sie die Erlaubnis haben.

mein Plugin ist in :(Pfad [dot] com/test) Ordner alles funktioniert gut darin aber ist für die Öffentlichkeit zugänglich.

Bisher habe ich von dem (Test/index.php) versucht haben, diesen Code:

// Load Joomla! configuration file 
require_once('../configuration.php'); 
// Create a JConfig object 
$config = new JConfig(); 
//import variables 
$dbhostname  = $config->host; 
$dbusername  = $config->user; 
$dbpassword  = $config->password; 
$dbdatabase  = $config->db; 
$dbprefix  = $config->dbprefix; 
$secret   = $config->secret; 

// Get these from your form... 

    $username_for_check = 'admin'; // this username should be in your database = change it 

    $password_for_check = 'passw'; //this password should be in your database encrypted = change it 

//connect to db 
    $mysqli = new mysqli($dbhostname,$dbusername,$dbpassword,$dbdatabase); 

    if ($result = $mysqli->query('SELECT j.username,j.password FROM '.$dbprefix.'users j WHERE j.username="'.$username_for_check.'" LIMIT 1;')) { 

     if ($result->num_rows == 0){ 
     echo 'Username does not exist.'; 
     } 
     else{ 
     while ($row = $result->fetch_object()) { 

      //Grab username and password from table #__users 
      $joomla_user = $row->username; 
      $joomla_pass = $row->password; 


      $pass_array = explode(':',$row->password);// <== Here not sure!! 
      //but it should be the magic behind it.. for me doesn't work in joomla 3.5 and above apparently as encryption method changed 
      //my password does not have a colon in between 

      //\\===\ Those are just echos to visually check if the password was matched /==//\\ 

      echo '[USER:] '.$joomla_user.'<br>'; 

      echo '[PASS:] '.$joomla_pass.'<br>'; 

      echo '[HASH:] '.$joomla_hash = $pass_array[0].'<br>'; 

      echo '[SALT:] '.$joomla_salt = $pass_array[1].'<br>'; 

      echo '[SECRET:] '.$secret.'<br>'; //secret maybe of help, just put it ready for testing 

      echo '[CHECK:] '.md5($password_for_check.$joomla_salt).'<br>'; 
      //=======================================================================// 
     } 

     if($joomla_hash == md5($password_for_check.$joomla_salt)){ //Old approch for validating according to various prehistoric posts 

      echo 'Username and password combination validated.'; 

     } 
     else{ 
      echo 'Invalid password for username.'; 
     } 

     } 

    } 
    else { 
    echo 'LOGIN VALIDATION: MySQL Error - '.$mysqli->error; 
    } 
    //close db 
    $mysqli->close(); 

Der Versuch, ein Spiel zurückzukehren und registrierte Benutzer zu überprüfen, bevor Sie fortfahren.

Ich hoffe jemand hat eine Lösung für diese auf 3.5 und höher.

Dank im Voraus

Antwort

0

den besten Weg, es ist es jemand helfen würde, wie diese Hoffnung zu tun herausgefunden:

<?php 
// Load Joomla! configuration file 
require_once('../configuration.php'); 
// Create a JConfig object 
$config = new JConfig(); 
//import variables 
$dbhostname  = $config->host; 
$dbusername  = $config->user; 
$dbpassword  = $config->password; 
$dbdatabase  = $config->db; 
$dbprefix  = $config->dbprefix; 

// Get these from your form... 
    $username_for_check = 'admin'; // this username should be in your database = change it 
    $password_for_check = '1234'; //this password should be in your database encrypted = change it 

    //Something like that from your form 
    //$username_for_check = $_POST['access_login']; 
    //$password_for_check = $_POST['access_password']; 
//connect to db 
    $mysqli = new mysqli($dbhostname,$dbusername,$dbpassword,$dbdatabase); 
    if ($result = $mysqli->query('SELECT j.username,j.password FROM '.$dbprefix.'users j WHERE j.username="'.$username_for_check.'" LIMIT 1;')) { 
     if ($result->num_rows == 0){ 
      echo 'Username does not exist.'; 
     } 
     else{ 
      while ($row = $result->fetch_object()) { 
       //Grab username and password from table #__users 
       $joomla_user = $row->username; 
       $joomla_pass = $row->password; 
      } 
      if(password_verify($password_for_check , $joomla_pass)){ 
       echo 'Username and password combination validated.'; 
      } 
      else{ 
       echo 'Invalid password for username.'; 
      } 
     } 
    } 
    else { 
     echo 'LOGIN VALIDATION: MySQL Error - '.$mysqli->error; 
    } 
    //close db 
    $mysqli->close(); 
?>