Ignore:
Timestamp:
Feb 20, 2014 3:03:59 AM (10 years ago)
Author:
anonymous
Message:

Completed integrating /branches/eli_branch into /trunk. Changes include:

  • Removed closing ?> from end of files
  • Upgrade old-style contructor methods to use construct() instead.
  • Class properties and methods defined as public, private, static or protected
  • Ensure code runs under E_ALL with only mysql_* deprecated warnings
  • Search for the '@' symbol anywhere it might be used to supress runtime errors, then replace with proper error recovery.
  • Run the php cli -l option to check files for syntax errors.
  • Bring tests up-to-date with latest version and methods of PHPUnit
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/lib/Auth_SQL.inc.php

    r465 r468  
    2828*/
    2929
    30 // Available encryption types for class Auth_SQL.
    31 define('AUTH_ENCRYPT_PLAINTEXT', 1);
    32 define('AUTH_ENCRYPT_CRYPT', 2);
    33 define('AUTH_ENCRYPT_SHA1', 3);
    34 define('AUTH_ENCRYPT_SHA1_HARDENED', 4);
    35 define('AUTH_ENCRYPT_MD5', 5);
    36 define('AUTH_ENCRYPT_MD5_HARDENED', 6);
    37 
    3830require_once dirname(__FILE__) . '/Email.inc.php';
    3931
    4032class Auth_SQL {
    4133
     34    // Available encryption types for class Auth_SQL.
     35    const ENCRYPT_PLAINTEXT = 1;
     36    const ENCRYPT_CRYPT = 2;
     37    const ENCRYPT_SHA1 = 3;
     38    const ENCRYPT_SHA1_HARDENED = 4;
     39    const ENCRYPT_MD5 = 5;
     40    const ENCRYPT_MD5_HARDENED = 6;
     41
    4242    // Namespace of this auth object.
    43     var $_ns;
     43    private $_ns;
    4444
    4545    // Static var for test.
    46     var $_authentication_tested;
     46    private $_authentication_tested;
    4747
    4848    // Parameters to be configured by setParam.
    49     var $_params = array();
    50     var $_default_params = array(
     49    private $_params = array();
     50    private $_default_params = array(
    5151
    5252        // Automatically create table and verify columns. Better set to false after site launch.
     
    6666        'db_login_table' => 'user_login_tbl',
    6767
    68         // The type of encryption to use for passwords stored in the db_table. Use one of the AUTH_ENCRYPT_* types specified above.
     68        // The type of encryption to use for passwords stored in the db_table. Use one of the Auth_SQL::ENCRYPT_* types specified above.
    6969        // Hardened password hashes rely on the same key/salt being used to compare encryptions.
    7070        // Be aware that when using one of the hardened types the App signing_key or $more_salt below cannot change!
    71         'encryption_type' => AUTH_ENCRYPT_MD5,
     71        'encryption_type' => self::ENCRYPT_MD5,
    7272
    7373        // The URL to the login script.
     
    127127     * @param optional array $params  A hash containing parameters.
    128128     */
    129     function Auth_SQL($namespace='')
     129    public function __construct($namespace='')
    130130    {
    131131        $app =& App::getInstance();
     
    153153     * @since   26 Aug 2005 17:09:36
    154154     */
    155     function initDB($recreate_db=false)
     155    public function initDB($recreate_db=false)
    156156    {
    157157        $app =& App::getInstance();
     
    253253     * @return bool true on success, false on failure
    254254     */
    255     function setParam($params)
     255    public function setParam($params)
    256256    {
    257257        if (isset($params['match_remote_ip_exempt_usernames'])) {
     
    274274     * @return mixed               Configured parameter value.
    275275     */
    276     function getParam($param)
     276    public function getParam($param)
    277277    {
    278278        $app =& App::getInstance();
     
    291291     * @access public
    292292     */
    293     function clear()
     293    public function clear()
    294294    {
    295295        $db =& DB::getInstance();
     
    326326     * @param mixed $val      Value to set variable to.
    327327     */
    328     function set($key, $val)
     328    public function set($key, $val)
    329329    {
    330330        if (!isset($_SESSION['_auth_sql'][$this->_ns]['user_data'])) {
     
    342342     * @return mixed          Value stored in session.
    343343     */
    344     function get($key, $default='')
     344    public function get($key, $default='')
    345345    {
    346346        if (isset($_SESSION['_auth_sql'][$this->_ns][$key])) {
     
    361361     * @return mixed  False if credentials not found in DB, or returns DB row matching credentials.
    362362     */
    363     function authenticate($username, $password)
     363    public function authenticate($username, $password)
    364364    {
    365365        $app =& App::getInstance();
     
    369369
    370370        switch ($this->_params['encryption_type']) {
    371         case AUTH_ENCRYPT_CRYPT :
     371        case self::ENCRYPT_CRYPT :
    372372            // Query DB for user matching credentials. Compare cyphertext with salted-encrypted password.
    373373            $qid = $db->query("
     
    378378            ");
    379379            break;
    380         case AUTH_ENCRYPT_PLAINTEXT :
    381         case AUTH_ENCRYPT_MD5 :
    382         case AUTH_ENCRYPT_SHA1 :
     380        case self::ENCRYPT_PLAINTEXT :
     381        case self::ENCRYPT_MD5 :
     382        case self::ENCRYPT_SHA1 :
    383383        default :
    384384            // Query DB for user matching credentials. Directly compare cyphertext with result from encryptPassword().
     
    412412     * @return boolean  Whether or not the credentials are valid.
    413413     */
    414     function login($username, $password)
     414    public function login($username, $password)
    415415    {
    416416        $app =& App::getInstance();
     
    421421        $this->clear();
    422422
    423         if (!$user_data = $this->authenticate($username, $password)) {
     423        if (!($user_data = $this->authenticate($username, $password))) {
    424424            // No login: failed authentication!
    425425            return false;
     
    539539     * @access public
    540540     */
    541     function isLoggedIn($user_id=null)
     541    public function isLoggedIn($user_id=null)
    542542    {
    543543        $app =& App::getInstance();
     
    671671     * @access public
    672672     */
    673     function requireLogin($message='', $type=MSG_NOTICE, $file=null, $line=null)
     673    public function requireLogin($message='', $type=MSG_NOTICE, $file=null, $line=null)
    674674    {
    675675        $app =& App::getInstance();
     
    693693     * @param  string   $reason      The reason for blocking the account.
    694694     */
    695     function blockAccount($user_id=null, $reason='')
     695    public function blockAccount($user_id=null, $reason='')
    696696    {
    697697        $app =& App::getInstance();
     
    723723     * @return boolean              True if the user is blocked, false otherwise.
    724724     */
    725     function isBlocked($user_id=null)
     725    public function isBlocked($user_id=null)
    726726    {
    727727        $db =& DB::getInstance();
     
    745745     * Unblocks a user in the db_table, and clears any blocked_reason.
    746746     */
    747     function unblockAccount($user_id=null)
     747    public function unblockAccount($user_id=null)
    748748    {
    749749        $db =& DB::getInstance();
     
    769769     * @return bool                 True if username exists.
    770770     */
    771     function usernameExists($username)
     771    public function usernameExists($username)
    772772    {
    773773        $db =& DB::getInstance();
     
    789789     * @return string               Username, or false if none found.
    790790     */
    791     function getUsername($user_id)
     791    public function getUsername($user_id)
    792792    {
    793793        $db =& DB::getInstance();
     
    813813     * patterns, at minimum the US State Department standard: cvcddcvc.
    814814     *
    815      * - x    a random upper or lower alpha character or digit
    816      * - C    a random upper or lower consonant
    817      * - V    a random upper or lower vowel
    818      * - c    a random lowercase consonant
    819      * - v    a random lowercase vowel
    820      * - d    a random digit
     815     * - x    A random upper or lower character, digit, or punctuation.
     816     * - C    A random upper or lower consonant.
     817     * - V    A random upper or lower vowel.
     818     * - c    A random lowercase consonant.
     819     * - v    A random lowercase vowel.
     820     * - d    A random digit.
    821821     *
    822822     * @param  string $pattern  a sequence of character types, above.
    823823     * @return string           a password
    824824     */
    825     function generatePassword($pattern='CvcdCvc')
     825    public function generatePassword($pattern='CvcdCvc')
    826826    {
    827827        $app =& App::getInstance();
     
    846846     *
    847847     */
    848     function encryptPassword($password, $salt=null)
     848    public function encryptPassword($password, $salt=null)
    849849    {
    850850        $app =& App::getInstance();
     
    855855
    856856        switch ($this->_params['encryption_type']) {
    857         case AUTH_ENCRYPT_PLAINTEXT :
     857        case self::ENCRYPT_PLAINTEXT :
    858858            return $password;
    859859            break;
    860860
    861         case AUTH_ENCRYPT_CRYPT :
     861        case self::ENCRYPT_CRYPT :
    862862            // If comparing plaintext password with a hash, provide first two chars of the hash as the salt.
    863863            return isset($salt) ? crypt($password, mb_substr($salt, 0, 2)) : crypt($password);
    864864            break;
    865865
    866         case AUTH_ENCRYPT_SHA1 :
     866        case self::ENCRYPT_SHA1 :
    867867            return sha1($password);
    868868            break;
    869869
    870         case AUTH_ENCRYPT_SHA1_HARDENED :
     870        case self::ENCRYPT_SHA1_HARDENED :
    871871            $hash = sha1($app->getParam('signing_key') . $password . $more_salt);
    872872            // Increase key strength by 12 bits.
     
    877877            break;
    878878
    879         case AUTH_ENCRYPT_MD5 :
     879        case self::ENCRYPT_MD5 :
    880880            return md5($password);
    881881            break;
    882882
    883         case AUTH_ENCRYPT_MD5_HARDENED :
     883        case self::ENCRYPT_MD5_HARDENED :
    884884            // Include salt to improve hash
    885885            $hash = md5($app->getParam('signing_key') . $password . $more_salt);
     
    901901     *
    902902     */
    903     function setPassword($user_id=null, $password)
     903    public function setPassword($user_id=null, $password)
    904904    {
    905905        $app =& App::getInstance();
     
    951951     * @return string            The user's new password.
    952952     */
    953     function resetPassword($user_id=null, $reason='')
     953    public function resetPassword($user_id=null, $reason='')
    954954    {
    955955        $app =& App::getInstance();
     
    10161016     * @return bool     true if user is a member of security zone, false otherwise
    10171017     */
    1018     function inClearanceZone($security_zone, $user_type='')
    1019     {
    1020         // return true; /// WTF?
     1018    public function inClearanceZone($security_zone, $user_type='')
     1019    {
    10211020        $zone_members = preg_split('/,\s*/', $security_zone);
    10221021        $user_type = empty($user_type) ? $this->get('user_type') : $user_type;
     
    10391038     * @param  constant $security_zone   string of comma delimited privileges for the zone
    10401039     */
    1041     function requireAccessClearance($security_zone, $message='')
     1040    public function requireAccessClearance($security_zone, $message='')
    10421041    {
    10431042        $app =& App::getInstance();
    10441043
    1045         // return true; /// WTF?
    10461044        $zone_members = preg_split('/,\s*/', $security_zone);
    10471045
     
    10971095// 128.0.0.0        10000000.00000000.00000000.00000000  /1
    10981096// 0.0.0.0          00000000.00000000.00000000.00000000  /0   IP space
    1099 ?>
Note: See TracChangeset for help on using the changeset viewer.