0

I'm making an Android app, and I need the users to log into the database belonging to joomla. I'm making a php but it does not work

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.

323go
  • 14,143
  • 6
  • 33
  • 41

3 Answers3

0

Joomla! 1.5 uses md5 to hash the passwords. When the passwords are created, they are hashed with a 32 character salt that is appended to the end of the password string. The password is stored as {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

Arun Unnikrishnan
  • 2,339
  • 2
  • 25
  • 39
0

Joomla uses md5 hash for password, but by using an external file you cant access the joomla resources because the architecture prevents external access. The other way round is using the user /password access the joomla basic login system programatically to grant acesss.

Anoop P S
  • 754
  • 1
  • 12
  • 31
0

You can use the following code to achieve your requirement.

In joomla standard you can create password using the following way

                     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.

using joomla default frame work like this

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. You can use joomla's

$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..

Community
  • 1
  • 1
Jobin
  • 8,238
  • 1
  • 33
  • 52