ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Pulling my hair out now trying to authenticate users from MRBS

October 12, 2012 5:40pm

Subscribe [2]
  • #1 / Oct 12, 2012 5:40pm

    joemo

    26 posts

    so i though i had this fixed and i just cant figure it

    I have been using MRBS (an open source booking system)  in conjunction with EE very successfully as a booking system

    check here http://mrbs.sourceforge.net/view_text.php?section=Documentation&file=AUTHENTICATION

    mrbs can authenticate the users against the EE database. It has worked fine until updated to latest EE have moved to a new server

    I have been using the following settings on MRBS

    this is from the config file

    /*******************
     * Database settings
     ******************/
    // Which database system: "pgsql"=PostgreSQL, "mysql"=MySQL,
    // "mysqli"=MySQL via the mysqli PHP extension
    $dbsys = "mysql";
    // Hostname of database server. For pgsql, can use "" instead of localhost
    // to use Unix Domain Sockets instead of TCP/IP.
    $db_host = "localhost";
    // Database name:
    $db_database = "mrbs";
    // Database login user name:
    $db_login = "root";
    // Database login password:
    $db_password = "MYPASSWORD";
    // Prefix for table names.  This will allow multiple installations where only
    // one database is available
    $db_tbl_prefix = "mrbs_";
    // Uncomment this to NOT use PHP persistent (pooled) database connections:
    // $db_nopersist = 1;
    
    
    
    $auth['db_ext']['db_system'] = 'mysql';
    $auth['db_ext']['db_host'] = 'localhost';
    $auth['db_ext']['db_username'] = 'root';
    $auth['db_ext']['db_password'] = 'MYPASSWORD';
    $auth['db_ext']['db_name'] = 'MY_EE_DATABASE_NAME';
    $auth['db_ext']['db_table'] = 'exp_members';
    $auth['db_ext']['column_name_username'] = 'username';
    $auth['db_ext']['column_name_password'] = 'password';
    // Either 'md5', 'sha1', 'crypt' or 'plaintext'
    $auth['db_ext']['password_format'] = 'sha1';


    have updated to the latest version the authentication no longer works i just get unknown user when i try to login to MRBS
    is there any changes that might effect this? The old database was on mysql 5.0.92 and the new database is on 5.5.25a

    it seems to connect because if i change the password I get a database failed to connect message, but mrbs always returns unknown user

    this is the code from MRBS to authenticate against another DB

    <?php
    /*****************************************************************************
    *
    *   File name       auth_db_ext.inc
    *
    *   Description     Authenticate users from a table in another database.
    *
    *   Notes           To use this authentication scheme, set in config.inc.php:
    *         $auth["type"]  = "db_ext";
    *                   Assumes passwords are stored in the other table in
    *                   plaintext, authValidateUser() will need to be changed if
    *                   the password is stored differently.
    *
    *   History
    *    Available in the source control system
    *
    ******************************************************************************/
    
    // $Id: auth_db_ext.inc 1115 2009-05-28 22:23:30Z jberanek $
    
    
    /* authValidateUser($user, $pass)
     * 
     * Checks if the specified username/password pair are valid
     * 
     * $user  - The user name
     * $pass  - The password
     * 
     * Returns:
     *   0        - The pair are invalid or do not exist
     *   non-zero - The pair are valid
     */
    
    function authValidateUser($user, $pass)
    {
      global $auth;
    
      $retval = 0;
    
      $user = strtolower($user);
    
      if (empty($auth['db_ext']['db_system']))
      {
        $auth['db_ext']['db_system'] = 'mysql';
      }
    
      $conn = sql_connect($auth['db_ext']['db_system'],
                          $auth['db_ext']['db_host'],
                          $auth['db_ext']['db_username'],
                          $auth['db_ext']['db_password'],
                          $auth['db_ext']['db_name']);
    
      $user = addslashes($user);
    
      $query = "SELECT " . $auth['db_ext']['column_name_password'] .
               " FROM " . $auth['db_ext']['db_table'] .
               " WHERE ". $auth['db_ext']['column_name_username'] . "='$user'";
    
      $r = sql_query($query, $conn);
    
      if ($r && (sql_count($r, $conn) == 1)) // force a unique match
      {
        $row = sql_row($r, 0, $conn);
    
        switch ($auth['db_ext']['password_format'])
        {
          case 'md5':
            if (md5($pass) == $row[0])
            {
              $retval = 1;
            }
            break;
    
          case 'sha1':
            if (sha1($pass) == $row[0])
            {
              $retval = 1;
            }
            break;
    
          case 'crypt':
            $recrypt = crypt($pass,$row[0]);
            if ($row[0] == $recrypt)
            {
              $retval = 1;
            }
            break;
    
          default:
            // Otherwise assume plaintext
    
            // Backwards-compatibility config option
            if ($auth['db_ext']['use_md5_passwords'] == 1)
            {
              $pass = md5($pass);
            }
    
            if ($pass == $row[0])
            {
              $retval = 1;
            }
            break;
        }
      }
    
      return $retval;
    }
    
    /* authGetUserLevel($user)
     * 
     * Determines the users access level
     * 
     * $user - The user name
     *
     * Returns:
     *   The users access level
     */
    function authGetUserLevel($user)
    {
      global $auth;
      $admins = $auth['admin'];
      // User not logged in, user level '0'
      if(!isset($user))
      {
        return 0;
      }
    
      // Check if the user is can modify
      for($i = 0; isset($admins[$i]); $i++)
      {
        if(strcasecmp($user, $admins[$i]) == 0)
        {
          return 2;
        }
      }
    
      // Everybody else is access level '1'
      return 1;
    }
    
    ?>

     


    any ideas at all about how to get to the bottom of this, I really need an equipment booking system back online for my students.
    mrbs did the job and integrated into out EE site.

    I am juts not sure what more to do to work it out, i just did a short php test that seemed to work ok so is it the way the passwords are stored?

    <?php
    
    $con = mysql_connect("localhost","root","MY_PASSWORD");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("EE", $con);
    
    $result = mysql_query("SELECT * FROM exp_members");
    
    while($row = mysql_fetch_array($result))
      {
      echo $row['username'] . " " . $row['password'];
      echo "
    ";
      }
    
    mysql_close($con);
    ?>

    Any help / pointers much appreciated

    joemo

  • #2 / Oct 13, 2012 9:16am

    joemo

    26 posts

    I think I have narrowed down to the password checking as MRBS with authenticate when i exchange the password for screen_name and
    enter my username and screen name in MRBS

    $auth['db_ext']['column_name_username'] = 'username';
    $auth['db_ext']['column_name_password'] = 'password';

    Is it no longer possible to authenticate ee members this way? is there a way of authenticating a member from outside the templating system?
    i have been assuming password stored sha1

    ?

    thanks joemo

     

     

  • #3 / Oct 13, 2012 10:06am

    joemo

    26 posts

    Ok I am going to refine and try.

    once logged in to upgraded EE my password is sha512 with salt?
    if this is correct does anyone know if i can add a section in the auth_db_ext.inc to work this.

    another case?

    case 'sha1':
            if (sha1($pass) == $row[0])
            {
              $retval = 1;
            }
            break;

    I am going to worry and google at this until i can come up with a solution.
    Another thought I had is if it is possible to do the authentication within EE and return the value MRBS is looking for

    Joemo

     

     

  • #4 / Oct 15, 2012 1:13pm

    Kevin Smith

    4784 posts

    Hi Joemo,

    Sorry to hear that you’re running up against this trouble. Unfortunately, since this so heavily involves a third-party system, there’s not much I can do to help here. Would you like me to move this thread over to the Community Help forum to see if anyone else can toss in and help here?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases