Changeset 111

Show
Ignore:
Timestamp:
04/19/07 09:53:21
Author:
danfreak
Message:

"FAL: improved login validatin security merging individual messages for wrong username or wrong password in just one message: wrong username or password"

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • FreakAuth/trunk/www/system/application/config/freakauth_light.php

    r93 r111  
    116116 
    117117        //  LOGIN 
    118 $config['FAL_user_name_field_validation_login'] = 'trim|required|xss_clean|username_login_check';          //name in login 
    119 $config['FAL_user_password_field_validation_login'] = 'trim|required|xss_clean|password_login_check';  //password in login 
     118$config['FAL_user_name_field_validation_login'] = 'trim|required|xss_clean';          //name in login 
     119$config['FAL_user_password_field_validation_login'] = 'trim|required|xss_clean';  //password in login 
    120120 
    121121        //  REGISTRATION 
  • FreakAuth/trunk/www/system/application/controllers/auth.php

    r93 r111  
    100100        $rules['user_name'] = $this->config->item('FAL_user_name_field_validation_login'); 
    101101        $rules['password'] = $this->config->item('FAL_user_password_field_validation_login'); 
     102        $rules['username_password'] = ''; 
    102103         
    103104        //------------------------------------- 
     
    113114        $this->fal_validation->set_rules($rules); 
    114115         
     116        //let's run the individual validation of username and password  
     117        $validation_response = $this->fal_validation->run(); 
     118         
     119        //if you change the keys of the validation rules 
     120        //remember to adjust the following 2 lines 
     121        //i.e. change $this->fal_validation->user_name to $this->fal_validation->your_user_name_key 
     122        echo $username_login = $this->fal_validation->user_name; 
     123        echo $password_login = $this->fal_validation->password; 
     124         
    115125        //everything went ok, let's log the user in and redirect him to the homepage 
    116         if ($this->fal_validation->run() && $this->freakauth_light->login()) 
     126        if ($validation_response==TRUE && $this->fal_validation->login_check($username_login, $password_login) && $this->freakauth_light->login()) 
    117127        { 
    118128            $role= $this->db_session->userdata('role'); 
  • FreakAuth/trunk/www/system/application/libraries/FAL_validation.php

    r108 r111  
    5656         
    5757        // -------------------------------------------------------------------- 
     58        /** 
     59         * Function using for login validation 
     60         * validates username and password simultaneulsy 
     61         * if they passed previous distinct/individual validation 
     62         * 
     63         * @param string $username_login   the username passed by previous validation 
     64         * @param string $password_login   the password passed by previous validation 
     65         * @return boolean 
     66         */ 
     67         
     68        function login_check($username_login, $password_login) 
     69        { 
     70                //Use the input username and checks against 'users' table 
     71        $query = $this->CI->UserModel->getUserByUsername($username_login); 
     72         
     73        if (($query != null) && ($query->num_rows() == 0)) 
     74            { 
     75                //debugging 
     76                //echo '<br>username not found<br>'; 
     77                $username_cond = false; 
     78                } 
     79                else  
     80                { 
     81                        //debugging 
     82                        //echo '<br>username found<br>'; 
     83                        $username_cond = true; 
     84                } 
     85                 
     86                //debugging 
     87                //echo isset($password_login) ? '<br>password set<br>' : '<br>not set<br>'; 
     88                //echo $password_login; 
     89                 
     90                if ($username_cond == true AND isset($password_login) AND $password_login!='') 
     91                { 
     92                //encrypts the random password using the md5 encryption 
     93                $encrypted_password = $this->CI->freakauth_light->_encode($password_login);                      
     94                $query = $this->CI->UserModel->getUserForLogin($username_login , $encrypted_password); 
     95                 
     96                if (($query != null) && ($query->num_rows() == 0)) 
     97                    { 
     98                        //we didn't find the password 
     99                        $pass_cond = FALSE; 
     100                        //debugging 
     101                        //echo '<br>password not found<br>'; 
     102                        } 
     103                        else  
     104                        { 
     105                                //we found the password 
     106                                $pass_cond = TRUE; 
     107                                //debugging 
     108                                //echo '<br>password found<br>'; 
     109                        } 
     110                } 
     111                //username not found or password empty 
     112                else  
     113                { 
     114                        $pass_cond = FALSE; 
     115                        //debugging 
     116                        //echo '<br>username not  found or password empty<br>'; 
     117                } 
     118                 
     119                //do we passed validation? 
     120                if ($username_cond == TRUE AND $pass_cond == TRUE) 
     121                { 
     122                        return true; 
     123                } 
     124                else  
     125                { 
     126                        //let's set the message 
     127                        $this->login_error_message = $this->_error_prefix.$this->CI->lang->line('FAL_invalid_username_password_message').$this->_error_suffix; 
     128                        return false; 
     129                } 
     130        } 
     131         
     132        // -------------------------------------------------------------------- 
    58133 
    59134        /** 
     
    96171    /** 
    97172     * RULES HELPER FUNCTION 
    98      * Password validation callback for login 
    99      * 
    100      * @access private 
    101      * @param varchar $value 
    102      * @return boolean 
    103      */ 
    104     function password_login_check($value) 
    105         {        
    106                 if (isset($this->username) AND $this->username!='') 
    107                 { 
    108                 //encrypts the random password using the md5 encryption 
    109                 $encrypted_password = $this->CI->freakauth_light->_encode($value);                       
    110                 $query = $this->CI->UserModel->getUserForLogin($this->username , $encrypted_password); 
    111                  
    112                 if (($query != null) && ($query->num_rows() == 0)) 
    113                     { 
    114                         $this->set_message('password_login_check', $this->CI->lang->line('FAL_invalid_password_message')); 
    115                             return false; 
    116                         } 
    117                         else {return true;} 
    118                 } 
    119                 else  
    120                 { 
    121                         $this->set_message('password_login_check', $this->CI->lang->line('FAL_username_first_password_message')); 
    122                         return false; 
    123                 } 
    124                  
    125         } 
    126          
    127         // -------------------------------------------------------------------- 
    128  
    129     /** 
    130      * RULES HELPER FUNCTION 
    131173     * Password validation callback for change password 
    132174     * 
     
    169211            return $this->is_valid_text($callback, $value, $this->CI->config->item('FAL_user_name_min'), $this->CI->config->item('FAL_user_name_max')); 
    170212        } 
    171          
    172         // -------------------------------------------------------------------- 
    173  
    174     /** 
    175      * RULES HELPER FUNCTION 
    176      * User name validation callback for login 
    177      * 
    178      * @access private 
    179      * @param varchar $value 
    180      * @return boolean 
    181      */ 
    182     function username_login_check($value) 
    183         {        
    184                 $this->username = $value;  
    185                  
    186                 //Use the input username and checks against 'users' table 
    187         $query = $this->CI->UserModel->getUserByUsername($value); 
    188          
    189         if (($query != null) && ($query->num_rows() == 0)) 
    190             { 
    191                 $this->set_message('username_login_check', $this->CI->lang->line('FAL_invalid_username_message')); 
    192                     return false; 
    193                 } 
    194                  
    195                 else {return true;} 
    196                          
    197         } 
    198          
    199          
    200213         
    201214        // -------------------------------------------------------------------- 
  • FreakAuth/trunk/www/system/application/views/FreakAuth_light/content/login.php

    r94 r111  
    11<fieldset><legend accesskey="D" tabindex="1"><?=$heading?></legend> 
     2<?=isset($this->fal_validation->login_error_message) ? $this->fal_validation->login_error_message : ''?> 
    23<?=form_open('auth/')?> 
    34<!--USERNAME--> 
     
    78                               'maxlength'=>'30',  
    89                               'size'=>'30', 
    9                                'value'=>(isset($this->fal_validation) ? $this->fal_validation->{'user_name'} : '')))?> 
     10                               'value'=>''))?> 
    1011    <?=(isset($this->fal_validation) ? $this->fal_validation->{'user_name'.'_error'} : '')?> 
    1112   </p> 
     
    1617                               'maxlength'=>'30',  
    1718                               'size'=>'30', 
    18                                'value'=>(isset($this->fal_validation) ? $this->fal_validation->{'password'} : '')))?> 
     19                               'value'=> ''))?> 
    1920     
    2021    <?=(isset($this->fal_validation) ? $this->fal_validation->{'password'.'_error'} : '')?> 
  • FreakAuth/trunk/www/system/language/english/freakauth_lang.php

    r87 r111  
    9090//------------------------------------------------------------------ 
    9191$lang['FAL_invalid_user_message'] = 'Invalid user.'; 
     92$lang['FAL_invalid_username_password_message'] = 'invalid username or password'; 
    9293$lang['FAL_invalid_username_message'] = 'Invalid username'; 
    9394$lang['FAL_invalid_password_message'] = 'Invalid password';