Changeset 126


Ignore:
Timestamp:
May 24, 2006 6:07:38 AM (18 years ago)
Author:
scdev
Message:

Q - Releasing tags/2.0.1, use branches/2.0 for maintaining.

Location:
tags/2.0.1
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • tags/2.0.1/lib/App.inc.php

    r108 r126  
    1616define('MSG_NOTICE', 4);
    1717define('MSG_SUCCESS', 8);
     18define('MSG_ALL', MSG_SUCCESS | MSG_NOTICE | MSG_WARNING | MSG_ERROR);
    1819
    1920require_once dirname(__FILE__) . '/Utilities.inc.php';
     
    11061107    function sslOff()
    11071108    {
     1109        if (!isset($this) || !is_a($this, 'App') && !is_subclass_of($this, 'App')) {
     1110            $this =& App::getInstance();
     1111        }
     1112
    11081113        if ('' != getenv('HTTPS')) {
    11091114            $this->dieURL('http://' . getenv('HTTP_HOST') . getenv('REQUEST_URI'), null, true);
  • tags/2.0.1/lib/Auth_SQL.inc.php

    r111 r126  
    251251            WHERE " . $this->_params['db_primary_key'] . " = '" . $this->getVal('user_id') . "'
    252252        ");
    253         $_SESSION['_auth_file'] = array('authenticated' => false);
     253        $_SESSION[$this->_sess] = array('authenticated' => false);
    254254    }
    255255
     
    300300        $this->initDB();
    301301
    302         // Query DB for user matching credentials.
    303         // FIXME: Cannot compare crypt style passwords this way.
    304         $qid = DB::query("
    305             SELECT *, " . $this->_params['db_primary_key'] . " AS user_id
    306             FROM " . $this->_params['db_table'] . "
    307             WHERE " . $this->_params['db_username_column'] . " = '" . DB::escapeString($username) . "'
    308             AND BINARY userpass = '" . DB::escapeString($this->encryptPassword($password)) . "'
    309         ");
     302        switch ($this->_params['encryption_type']) {
     303        case AUTH_ENCRYPT_CRYPT :
     304            // Query DB for user matching credentials. Compare cyphertext with salted-encrypted password.
     305            $qid = DB::query("
     306                SELECT *, " . $this->_params['db_primary_key'] . " AS user_id
     307                FROM " . $this->_params['db_table'] . "
     308                WHERE " . $this->_params['db_username_column'] . " = '" . DB::escapeString($username) . "'
     309                AND BINARY userpass = ENCRYPT('" . DB::escapeString($password) . "', LEFT(userpass, 2)))
     310            ");
     311            break;
     312        case AUTH_ENCRYPT_PLAINTEXT :
     313        case AUTH_ENCRYPT_MD5 :
     314        case AUTH_ENCRYPT_SHA1 :
     315        default :
     316            // Query DB for user matching credentials. Directly compare cyphertext with result from encryptPassword().
     317            $qid = DB::query("
     318                SELECT *, " . $this->_params['db_primary_key'] . " AS user_id
     319                FROM " . $this->_params['db_table'] . "
     320                WHERE " . $this->_params['db_username_column'] . " = '" . DB::escapeString($username) . "'
     321                AND BINARY userpass = '" . DB::escapeString($this->encryptPassword($password)) . "'
     322            ");
     323            break;
     324        }
    310325
    311326        // Return user data if found.
     
    528543                $expire_reasons[] = 'idle_timeout expired';
    529544            }
    530             if ($_SESSION['_auth_file']['remote_ip'] != getRemoteAddr() && !$user_in_trusted_network) {
     545            if ($_SESSION[$this->_sess]['remote_ip'] != getRemoteAddr() && !$user_in_trusted_network) {
    531546                $expire_reasons[] = sprintf('remote_ip not matched (%s != %s)', $_SESSION[$this->_sess]['remote_ip'], getRemoteAddr());
    532547            }
     
    682697     *
    683698     */
    684     function encryptPassword($password)
     699    function encryptPassword($password, $salt=null)
    685700    {
    686701        switch ($this->_params['encryption_type']) {
     
    690705
    691706        case AUTH_ENCRYPT_CRYPT :
    692             return crypt($password);
     707            // If comparing clear-text password with encrypted text, provide encrypted text as the salt.
     708            return isset($salt) ? crypt($password, substr($salt, 0, 2)) : crypt($password);
    693709            break;
    694710
     
    720736            WHERE " . $this->_params['db_primary_key'] . " = '" . DB::escapeString($user_id) . "'
    721737        ");
     738       
     739        if (mysql_affected_rows(DB::getDBH()) != 1) {
     740            App::logMsg(sprintf('setPassword failed to update password for user %s', $user_id), LOG_NOTICE, __FILE__, __LINE__);
     741        }
    722742    }
    723743
  • tags/2.0.1/lib/Email.inc.php

    r114 r126  
    281281        if (mail($final_to, $this->_params['subject'], $final_body, $final_headers, $envelope_sender_header)) {
    282282            App::logMsg(sprintf('Email successfully sent to %s', $final_to), LOG_DEBUG, __FILE__, __LINE__);
    283             return true
     283            return true;
    284284        } else {
    285285            App::logMsg(sprintf('Email failure with parameters: %s, %s, %s, %s', $final_to, $this->_params['subject'], str_replace("\r\n", '\r\n', $final_headers), $envelope_sender_header), LOG_NOTICE, __FILE__, __LINE__);
  • tags/2.0.1/tests/Auth_FileTest.php

    r42 r126  
    2323        require dirname(__FILE__) . '/_config.inc.php';
    2424        require_once '../lib/Auth_File.inc.php';
    25         $this->Auth_File =& new Auth_File(array('htpasswd_file' => dirname(__FILE__) . '/_test_htpasswd'));
     25        $this->Auth_File =& new Auth_File('test');
     26        $this->Auth_File->setParam(array('htpasswd_file' => dirname(__FILE__) . '/_test_htpasswd'));
    2627    }
    2728
     
    4445        $result = $this->Auth_File->login('testuser', 'testpass');
    4546        $this->assertTrue($result, 'testuser login failed.');
    46         $this->assertTrue($_SESSION['_auth']['authenticated'], 'testuser authentication not found in session.');
     47        $this->assertTrue($_SESSION['_auth_test']['authenticated'], 'testuser authentication not found in session.');
    4748    }
    4849
     
    5152        $result = $this->Auth_File->login('testuser', 'testpass');
    5253        $this->Auth_File->clearauth();
    53         $this->assertFalse($_SESSION['_auth']['authenticated'], 'testuser authentication not false in session.');
     54        $this->assertFalse($_SESSION['_auth_test']['authenticated'], 'testuser authentication not false in session.');
    5455    }
    5556
  • tags/2.0.1/tests/Auth_SQLTest.php

    r42 r126  
    2929            'db_login_table'    => 'test_login_tbl',
    3030            'login_url'         => '/login.php',
    31             'blocking'          => true
     31            'blocking'          => true,
     32            'encryption_type' => AUTH_ENCRYPT_SHA1,
    3233        ));
    3334
     
    4647            ) VALUES (
    4748                'testuser',
    48                 md5('testpass'),
     49                '" . $this->Auth_SQL->encryptpassword('testpass') . "',
    4950                'John',
    5051                'Doe',
     
    185186    function test_encryptpassword()
    186187    {
     188        $this->Auth_SQL->setParam(array('encryption_type' => AUTH_ENCRYPT_MD5));
    187189        $result = $this->Auth_SQL->encryptpassword('123');
    188190        $this->assertEquals('202cb962ac59075b964b07152d234b70', $result);
     191
     192        $this->Auth_SQL->setParam(array('encryption_type' => AUTH_ENCRYPT_SHA1));
     193        $result = $this->Auth_SQL->encryptpassword('123');
     194        $this->assertEquals('40bd001563085fc35165329ea1ff5c5ecbdbbeef', $result);
     195
     196        $this->Auth_SQL->setParam(array('encryption_type' => AUTH_ENCRYPT_PLAINTEXT));
     197        $result = $this->Auth_SQL->encryptpassword('123');
     198        $this->assertEquals('123', $result);
     199
     200        $this->Auth_SQL->setParam(array('encryption_type' => AUTH_ENCRYPT_CRYPT));
     201        $result = $this->Auth_SQL->encryptpassword('123', 'saltstring');
     202        $this->assertEquals('saEZ6MlWYV9nQ', $result);
    189203    }
    190204
     
    197211        ");
    198212        list($pass) = mysql_fetch_row($qid);
    199         $this->assertEquals('202cb962ac59075b964b07152d234b70', $pass);
     213        $this->assertEquals('40bd001563085fc35165329ea1ff5c5ecbdbbeef', $pass);
    200214    }
    201215
  • tags/2.0.1/tests/RecordLockTest.php

    r42 r126  
    4949            ) VALUES (
    5050                'testuser',
    51                 md5('testpass'),
     51                '" . $this->Auth_SQL->encryptpassword('testpass') . "',
    5252                'John',
    5353                'Doe',
     
    5656            )
    5757        ");
    58         $this->Auth_SQL->login('testuser', 'testpass');
     58        if (!$this->Auth_SQL->login('testuser', 'testpass')) {
     59            trigger_error('Test user not logged in.', E_USER_WARNING);
     60        }
    5961
    6062        $this->RecordLock =& RecordLock::getInstance($this->Auth_SQL);
  • tags/2.0.1/tests/_config.inc.php

    r43 r126  
    2929    'log_screen_priority' => LOG_WARNING,
    3030    'error_reporting' => E_ALL,
     31    'signing_key' => 'atestsaltkey',
    3132));
    3233
  • tags/2.0.1/tests/run_tests.sh

    r53 r126  
    77for foo in *Test.php;
    88do
    9     /usr/local/bin/php $foo;
     9    php4 $foo;
    1010done;
Note: See TracChangeset for help on using the changeset viewer.