[英]login user joomla in external php
I'm making an Android app, and I need the users to log into the database belonging to joomla. 我正在制作一个Android应用程序,我需要用户登录到属于joomla的数据库。 I'm making a php but it does not work 我正在制作php,但无法正常工作
What do you think of the code? 您如何看待代码? would you change? 你会改变吗?
<?php
/**
* Database config variables
*/
define("DB_HOST", "localhost");
define("DB_USER", "root");//cambiar por el nombre de usuario definido en la configuracion de la BD.
define("DB_PASSWORD", "");//Modificar por el password elegido
define("DB_DATABASE", "gestorrecursos");//Nombre de la base de datos reemplazar si se utilizo otro diferente al mencionado en el tutorial.
<?php
class funciones_BD {
private $db;
// constructor
function __construct() {
require_once 'connectbd.php';
// connecting to database
$this->db = new DB_Connect();
$this->db->connect();
}
// destructor
function __destruct() {
}
/**
* agregar nuevo usuario
*/
public function adduser($username, $password,$id) {
$result = mysql_query("INSERT INTO ocbup_users(username,password,id) VALUES('$username', '$password',$id)");
// check for successful store
if ($result) {
return true;
} else {
return false;
}
}
/**
* Verificar si el usuario ya existe por el username
*/
public function isuserexist($username) {
$result = mysql_query("SELECT username from ocbup_users WHERE username = '$username'");
$num_rows = mysql_num_rows($result); //numero de filas retornadas
if ($num_rows > 0) {
// el usuario existe
return true;
} else {
// no existe
return false;
}
}
public function login($user,$passw){
$result=mysql_query("SELECT COUNT(*) FROM ocbup_users WHERE username='$user' AND password='$passw' ");
$count = mysql_fetch_row($result);
/*como el usuario debe ser unico cuenta el numero de ocurrencias con esos datos*/
if ($count[0]==0){
return true;
}else{
return false;
}
}
}
?>
I appreciate your help and patience. 感谢您的帮助和耐心。
Joomla! Joomla! 1.5 uses md5 to hash the passwords. 1.5使用md5哈希密码。 When the passwords are created, they are hashed with a 32 character salt that is appended to the end of the password string. 创建密码后,会使用32个字符的盐对它们进行哈希处理,并在密码字符串的末尾附加盐。 The password is stored as {TOTAL HASH}:{ORIGINAL SALT}. 密码存储为{TOTAL HASH}:{ORIGINAL SALT}。
To see how this is tested for authentication take a look at plugins/authentication/joomla.php lines 80-116.use the same functionality for ur app login 要查看如何对此进行身份验证测试,请查看plugins / authentication / joomla.php第80-116行。使用与您的应用登录相同的功能
Joomla uses md5 hash for password, but by using an external file you cant access the joomla resources because the architecture prevents external access. Joomla使用md5哈希作为密码,但是通过使用外部文件,您无法访问joomla资源,因为该体系结构阻止了外部访问。 The other way round is using the user /password access the joomla basic login system programatically to grant acesss. 另一种方法是使用用户/ password以编程方式使用joomla基本登录系统来授予访问权限。
You can use the following code to achieve your requirement. 您可以使用以下代码来满足您的要求。
In joomla standard you can create password using the following way 在joomla standard中,您可以使用以下方式创建密码
jimport('joomla.user.helper');
$salt = JUserHelper::genRandomPassword(32);
$crypt = JUserHelper::getCryptedPassword($password_choose, $salt);
$password = $crypt.':'.$salt;
you mention that you are accessing from external file(or programs) then if you have joomla installation on other side you can access it from outside the joomla structure. 您提到要从外部文件(或程序)进行访问,那么如果在另一侧安装了joomla,则可以从joomla结构外部进行访问。
using joomla default frame work like this 使用joomla默认框架是这样的
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );//this is when we are in the root
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
Use this file in root joomla installation and include joomla frame work,then password creation. 在root joomla安装中使用此文件,并包含joomla框架,然后创建密码。 You can use joomla's 您可以使用joomla的
$app->login($credentional,$option);
for login system. 用于登录系统。
You can find many similar question in stack overflow try to search more.. 您可以在堆栈溢出中找到许多类似的问题,尝试进行更多搜索。
take look at this Hope this will help you.. 看看这个希望对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.