2014-02-08 3 views
2

시뮬레이션 질문에서 코드를 사용하여 게임에서 사용자에게 Joomla에 로그인하려고합니다. 제 문제는 긍정적 인 검증을하지 못한다는 것입니다.Joomla의 외부 로그인 확인

나는 이전의 joomla 3.2에서 simular questions에 주어진 솔루션으로 작업 한 내 원본 스크립트를 변환하는 데 어려움을 겪고 있었기 때문에이 테스트 스크립트를 만들었습니다.

'test'라는 이름의 사용자를 'test'라는 이름으로 만들고 'phpMyAmdin'의 암호화 된 pw를 스크립트에 복사했습니다. Joomla와이 웹 사이트에서 찾을 수있는 모든 정보에 따르면 내 pasword 검증은 성공적이어야하지만 실패합니다. 나는 뭔가를 놓치고 있습니까? 아니면 여기서 무슨 일이 일어나고 있습니까?

<?php 
define('_JEXEC', 1); 
define('JPATH_BASE', "../public_html"); 
define('DS', DIRECTORY_SEPARATOR); 

require_once ("instellingen.php"); 
require_once (JPATH_BASE .DS.'includes'.DS.'defines.php'); 
require_once (JPATH_BASE .DS.'includes'.DS.'framework.php'); 

$mainframe =& JFactory::getApplication('site'); 
$mainframe->initialise(); 

// created a test username with test as password in joomla 
$username = "test"; 
$password = "test"; 
$dbPW  = "$P$DxdrgIwlYqFE23mQjYvgvTNO3zoVN40"; // copied from phpMyAdmin 
$id   = JUserHelper::getUserId($username); 
echo "$id"; //<-- matches value shown in phpMyAdmin 

if(JUserHelper::verifyPassword($password, $dbPW, $id)) 
{ 
    echo "succesfull Login!"; 
} 
else 
{ 
    echo "failed Login!"; 
} 
?> 

답변

4

일부 general PHP knowledge about strings variables and quotes와 가진 당신의 development system properly configured 확실히 당신은 문제의이 종류를 통해 얻을 수 있습니다.

이제 실수를 발견했기를 바랍니다. 이 당신을 도움이된다면, 나는 Joomla는 다음과 같이 작동하는 암호화 알고리즘이 있다고 생각

<?php 
/** 
* Joomla! External authentication script 
* 
* @author vdespa 
* Version 1.0 
* 
* Code adapted from /index.php 
* 
* @package Joomla.Site 
* 
* @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. 
* @license GNU General Public License version 2 or later; see LICENSE.txt 
*/ 

if (version_compare(PHP_VERSION, '5.3.1', '<')) 
{ 
    die('Your host needs to use PHP 5.3.1 or higher to run this version of Joomla!'); 
} 

/** 
* Constant that is checked in included files to prevent direct access. 
* define() is used in the installation folder rather than "const" to not error for PHP 5.2 and lower 
*/ 
define('_JEXEC', 1); 

if (file_exists(__DIR__ . '/defines.php')) 
{ 
    include_once __DIR__ . '/defines.php'; 
} 

if (!defined('_JDEFINES')) 
{ 
    define('JPATH_BASE', __DIR__); 
    require_once JPATH_BASE . '/includes/defines.php'; 
} 

require_once JPATH_BASE . '/includes/framework.php'; 

// Instantiate the application. 
$app = JFactory::getApplication('site'); 

// JFactory 
require_once (JPATH_BASE .'/libraries/joomla/factory.php'); 


// Hardcoded for now 
$credentials['username'] = 'admin'; 
$credentials['password'] = 'admin'; 

/** 
* Code adapted from plugins/authentication/joomla/joomla.php 
* 
* @package  Joomla.Plugin 
* @subpackage Authentication.joomla 
* 
* @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. 
* @license  GNU General Public License version 2 or later; see LICENSE.txt 
*/ 

// Get a database object 
$db = JFactory::getDbo(); 
$query = $db->getQuery(true) 
    ->select('id, password') 
    ->from('#__users') 
    ->where('username=' . $db->quote($credentials['username'])); 

$db->setQuery($query); 
$result = $db->loadObject(); 

if ($result) 
{ 
    $match = JUserHelper::verifyPassword($credentials['password'], $result->password, $result->id); 

    if ($match === true) 
    { 
     // Bring this in line with the rest of the system 
     $user = JUser::getInstance($result->id); 
     var_dump($user); 
     echo 'Joomla! Authentication was successful!'; 
    } 
    else 
    { 
     // Invalid password 
     // Prmitive error handling 
     die('Invalid password'); 
    } 
} else { 
    // Invalid user 
    // Prmitive error handling 
    die('Cound not find user in the database'); 
} 
+1

덕분에 작동있어 (더 높은 버전을 사용하는 경우 I 줌라 2.5 사용은, 당신은 참조로 걸릴 수 있습니다) 않았다 , 내가 다른 견적을하고 더 나은 지금 그 종류를 얻을처럼 PHP의 몇 가지 기본적인 지식을 놓친 것 같습니다 :) – Bluestrike

+0

와우, 내가 코멘트를해야합니다! 이것은 여전히 ​​joomla 3.x.x 버전에서 작동합니다. – Jorius

1

을 : : 아래

당신을 위해 작동해야 솔루션입니다

  1. 당신은 사용자를 생성을 $user

  2. 암호를 지정하십시오. $password

  3. 줌라! A부터 Z a부터 z까지 그리고 0에서 9까지의 32 문자의 의사 무작위 배열을 만들고이 배열을 호출하십시오. $salt

  4. 줌라! $hash이라는 변수를 만들어서 변수 사용자와 소금을 연결하고이 모든 것에서 md5를 얻습니다. ... $hash = md5($user.$salt)

  5. 줌라! 저장 당신이 당신의 데이터베이스를 체크 아웃 할 때 암호는 다음과 같습니다 왜 다시 형식으로 해시 후 2 점을 연결 한 후, 소금, 인 암호 .... $hash.":".$salt

  6. : 3977807f631949e190966ae148a073ee:8z2Geal1qzizkhSTN6hP4fMrnnRxXbrj

Joomla 사이트에 내 Joomla 사이트를 연결하여 Joomla를 시작하려고합니다! 데시벨,하지만 변수를 분할하는 것은 ... 내가 원하는 사람에 대한 코드를 게시 할 예정입니다, 그것이 작동되도록하는

login.php

참고 : login.php 파일은 수행하는 기존의 암호 사이의 비교 내가 가야하기 때문에 줌라의 DB는, 그것을 암호화하여 보낼하지 않습니다, 나는 또한 내가 스페인 부분을 변환합니다, 추가 파일 내일이 주석을 편집하려고합니다, 죄송합니다 나는

conectar(); 
$myusername=$_POST['username']; 
$mypassword=$_POST['password']; 
$myusername = stripslashes($myusername); 
$mypassword = stripslashes($mypassword);  
$myusername = mysql_real_escape_string($myusername); 
$mypassword = mysql_real_escape_string($contrasena); 
if (isset($_POST['username'])) 
    { 
    $pass="SELECT * FROM users WHERE username='$myusername'"; 
    $result=mysql_query($pass); 
    $count=mysql_num_rows($result); 
    $row=mysql_fetch_array($result); 
    $pass=$row["password"]; 
    list($hash,$salt) = explode(":",$pass); //split the bd password 
    $cripto = md5($mypassword.$salt); //md5 into pass+salt 
    if (($hash==$cripto) && ($count==1)) 
     { 
     echo "true"; 
     session_start(); 
     $_SESSION['idUsuario'] = $row['idUser']; 
     $_SESSION['username'] = $myusername; 
     $_SESSION['password'] = $pass; 
     $_SESSION['rolUser'] = $row['rol']; 
     //header("location:login_success.php"); 
     } 
    else 
    { 
     echo "false"; 
    } 
} 
else 
    { 
    echo "false"; 
    } 
desconectar(); 
?> 

멕시코의 xD에서 왔어요 관객.PHP

또한 당신에게 단지

<?php 
function conectar(){ 

    $db_host="localhost"; 
    $db_usuario="root"; 
    $db_password=""; 
    $db_nombre="joomla"; 
    $conexion = @mysql_connect($db_host, $db_usuario, $db_password) or die(mysql_error()); 
    if (!$conexion) { 
     die('Error in connection: ' . mysql_error()); 
    } 
    else{ 
     //echo "<div class='success'> Conectado satisfactoriamente </div>";  
     $db = @mysql_select_db($db_nombre, $conexion) or die(mysql_error()); 
    } 
} 
function desconectar() 
{ 
    @mysql_close($conexion); 
} 
?> 

마지막으로 DB에 연결을 수행 내 conectar() 코드를 보여준다는 crypter는,이 같은 것입니다 :

crypter.php

<?php 
function pseudoRandom($values) 
{ 
$values = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890"; 
$chainNumber=$values; 
$originalPassword = ""; 
for($i=0;$i<$chainNumber;$i++) 
    { 
    $originalPassword .= substr($values,rand(0,strlen($values)),1); 
    } 
return $originalPassword; 
} 
$originalPassword = ’caca’; 
$salt=pseudoRandom(32); 
$hash=md5($cadena.$salt); 
$finalPassword=$hash.”:”.$salt; 
?> 
0

을 사용하여 라이브러리에서이 JCryptPasswordSimple->verify($postpassword,$dbpasswordhash)/줌라/토굴/암호/simple.php

0

joomla (3.x)의 최신 버전을 보려면 아래 스 니펫을 사용하십시오

jimport ('joomla.user.helper');

// Hardcoded for now 
$credentials['username'] = 'admin'; 
$credentials['password'] = 'admin'; 

//create a new password or load it from the database using the user, you might need to change the encryption method 
$salt = JUserHelper::genRandomPassword(32); 
$crypt = JUserHelper::getCryptedPassword($credentials['password'] , $salt, 'md5-hex'); 
$password = $crypt.':'.$salt; 


$match = JUserHelper::verifyPassword($credentials['password'], $password); 

if ($match === true){ 
    echo 'Joomla! Authentication was successful!'; 
}else{ 
    // Invalid password 
    // Prmitive error handling 
    die('Invalid password'); 
} 
0

I 줌라의 외부에서, 로그인 페이지

<?php 

//this xxx.php is outside of Joomla root 
//and Joomla root is in ./login folder 

define('_JEXEC', 1); 
define('JPATH_BASE', './login'); 

// Required Files 
require_once (JPATH_BASE . '/includes/defines.php'); 
require_once (JPATH_BASE . '/includes/framework.php'); 

// To use Joomla's Database Class 
require_once (JPATH_BASE .'/libraries/joomla/factory.php'); 

/********* POST login data from some where *********/ 
if(isset($_POST['uname']) && isset($_POST['psw'])) { 

    $credentials['username'] = trim($_POST['uname']); 
    $credentials['password'] = trim($_POST['psw']); 

    if(class_exists(JFactory)) { 

     $app = JFactory::getApplication('site');  

     // Get a database object 
     $db  = JFactory::getDbo(); 
     $query = $db->getQuery(true); 

     $query->select('id, password'); 
     $query->from('#__users'); 
     $query->where('username=' . $db->quote($credentials['username'])); 

     $db->setQuery($query); 
     $result = $db->loadObject(); 

     if ($result) 
     { 
      $match = JUserHelper::verifyPassword($credentials['password'], $result->password, $result->id); 

      if ($match === true) 
      { 
       $user = JUser::getInstance($result->id); // Bring this in line with the rest of the system 
       $app->login($credentials); 

       echo ("This user is logged in and Joomla also logged in! "); 
      } 
      else 
      { 
       echo ("User name and password not match! "); 
      } 
     } 
     else 
     { 
      echo ("THE USER IS NOT REGISTERED! "); 
     } 
    } 
} 

?>