Show
Ignore:
Timestamp:
10/22/07 15:06:20 (5 years ago)
Author:
benoitg
Message:
  • Major security fix: Fix the authenticator for a security breach where a user could get Internet access using an empty username. LocalUser? and LDAP were definitely vulnerable, RADIUS may have been.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog-auth/wifidog/classes/Authenticators/AuthenticatorLocalUser.php

    r1249 r1304  
    107107    public function login($username, $password, &$errmsg = null) 
    108108    { 
    109          
     109        //echo "DEBUG:  login($username, $password, $errmsg)<br/>"; 
    110110        $db = AbstractDb::getObject(); 
    111111 
     
    114114 
    115115        $username = $db->escapeString($username); 
    116         $password = $db->escapeString($password); 
    117         $password_hash = User::passwordHash($_REQUEST['password']); 
    118  
    119         $sql = "SELECT user_id FROM users WHERE (username='$username' OR email='$username') AND account_origin='".$this->getNetwork()->getId()."' AND pass='$password_hash'"; 
    120         $db->execSqlUniqueRes($sql, $user_info, false); 
    121  
    122         if ($user_info != null) { 
    123             $user = User::getObject($user_info['user_id']); 
    124  
    125             if ($user->isUserValid($errmsg)) { 
    126                 $retval = &$user; 
    127                 User::setCurrentUser($user); 
    128                 $errmsg = _("Login successfull"); 
    129             } else { 
    130                 $retval = false; 
    131                 //Reason for refusal is already in $errmsg 
    132             } 
    133         } else { 
    134             /* 
    135              * This is only used to discriminate if the problem was a 
    136              * non-existent user of a wrong password. 
    137              */ 
    138             $user_info = null; 
    139             $db->execSqlUniqueRes("SELECT * FROM users WHERE (username='$username' OR email='$username') AND account_origin='".$this->getNetwork()->getId()."'", $user_info, false); 
    140  
    141             if ($user_info == null) { 
    142                 $errmsg = _('Unknown username or email'); 
    143             } else { 
    144                 $errmsg = _('Incorrect password (Maybe you have CAPS LOCK on?)'); 
    145             } 
    146  
     116        if (empty($username)) { 
     117            $errmsg .= sprintf(_("Fatal error:  Username cannot be empty")); 
    147118            $retval = false; 
    148119        } 
    149  
     120        else{ 
     121            $password = $db->escapeString($password); 
     122            $password_hash = User::passwordHash($_REQUEST['password']); 
     123 
     124            $sql = "SELECT user_id FROM users WHERE (username='$username' OR email='$username') AND account_origin='".$this->getNetwork()->getId()."' AND pass='$password_hash'"; 
     125            $db->execSqlUniqueRes($sql, $user_info, false); 
     126 
     127            if ($user_info != null) { 
     128                $user = User::getObject($user_info['user_id']); 
     129 
     130                if ($user->isUserValid($errmsg)) { 
     131                    $retval = &$user; 
     132                    $errmsg = _("Login successfull"); 
     133                } else { 
     134                    $retval = false; 
     135                    //Reason for refusal is already in $errmsg 
     136                } 
     137            } else { 
     138                /* 
     139                 * This is only used to discriminate if the problem was a 
     140                 * non-existent user of a wrong password. 
     141                 */ 
     142                $user_info = null; 
     143                $db->execSqlUniqueRes("SELECT * FROM users WHERE (username='$username' OR email='$username') AND account_origin='".$this->getNetwork()->getId()."'", $user_info, false); 
     144 
     145                if ($user_info == null) { 
     146                    $errmsg = _('Unknown username or email'); 
     147                } else { 
     148                    $errmsg = _('Incorrect password (Maybe you have CAPS LOCK on?)'); 
     149                } 
     150 
     151                $retval = false; 
     152            } 
     153        } 
     154        User::setCurrentUser($retval); 
    150155        return $retval; 
    151156    }