EllisLab text mark
Advanced Search
     
Major form validation error messaging troubles
Posted: 04 October 2012 12:29 PM   [ Ignore ]
Joined: 2012-10-03
49 posts

Hello -

I have a login form that requires email and password. When I submit the form with both fields empty, the proper error messages appear, however when I put a CORRECT email address and a INCORRECT password, “invalid email” error pops up and no error displays for the password.

So basically the only time I can get “invalid password” is when I submit the form empty.


Here is my view(form):

<?php
    
    
echo form_open('auth/validate_credentials_login');
    echo 
"<span class='errors_login'>";
    echo 
form_error('email_login');
    echo 
"</span>";
    echo 
form_label('','Email''email_login');
    
$data = array( 'name' => 'email''class' => 'input''placeholder' => 'Email');
    echo 
form_input($dataset_value('email_login'));
    echo 
"<span class='errors_login'>";
    echo 
form_error('password_login');
    echo 
"</span>";
    echo 
form_label('''Password''password_login');
    
$data = array( 'name' => 'password_login''class' => 'input''placeholder' => 'Password');
    echo 
form_password($dataset_value('sha1(password_login)'));
    echo 
form_submit('submit_login''Login');
    echo 
form_close();
    
    
?> 

and here is my controller:

function validate_credentials_login()
  
{
   
// WHEN THE VIEW IS LOADED THIS FUNCTION IS CALLED AND LOADS MODEL AS WELL AS DEFINES THE SALT VARIABLE AND LOADS THE ENCRYPTING HELPER LIBRARY
   
   
$this->load->library('encrypt');
   
$this->load->helper('url');
   
$this->load->library('form_validation');
   
$this->form_validation->set_rules('email_login''Email''required|is_unique[users.email]');
   
$this->form_validation->set_rules('password_login''Password''required');
   
$this->load->library('session');
   
$this->load->model('user_model''um');
   
$login $this->input->post('submit_login');
   
   
 
    if(
$login{
    
    $user 
$this->um->validate_home_login(array('email' => $this->input->post('email_login')));
    if( 
$user {

     
// CHECK THE USER'S PASSWORD AGAINST THE ONE FROM THE LOGIN FORM
     
if($user->password == $this->encrypt->sha1$user->salt $this->encrypt->sha1($this->input->post('password_login')))) {
      $this
->session->set_userdata(array(
       
'email' => $this->input->post('email_login')
      ));
      
redirect('account/dashboard');
      exit;
     
}
    }
   }
  
   
if($this->form_validation->run() == FALSE){
   $data[
'main_content''home/home_page';
   
$this->load->view('includes/templates/home_page_template'$data);
  
}
 
 } 

any help is greatly appreciated. Thanks in advance.

 
Posted: 06 October 2012 11:26 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2009-04-15
453 posts

is_unique[users.email]

doesn’t belong in a login function. it is saying, “the email you passed is already in the database, so you can’t use it”. if you look in the source code you’ll understand better what it is doing

this would be appropriate for a registration form.

(BTW - this section is for asking about possible bugs in the CI framework, not troubleshooting your own code. please use the “Code” area for this)

 Signature 

Code By Jeff

Mahana Messaging Library

Problem with your query? Did you run

$this->db->last_query(); 

before you came to the forums for help?