2012-01-01 90 views
1

我已在CodeIgniter(電子郵件/密碼)中設置了我的登錄功能。電子郵件字段正在根據數據庫正確驗證,但只要電子郵件被驗證,任何密碼都被接受 - 即使是空白密碼。CodeIgniter密碼未針對數據庫進行驗證

我需要弄清楚爲什麼只有電子郵件字段正在檢查數據庫以及如何獲取密碼字段以驗證數據庫。

補充工具欄:我打算接下來對密碼進行加密,但要確保該字段首先針對數據庫進行驗證。然後我將添加安全層。

從登錄控制器:

function login_validation() 

{ 
    $this->load->model('foo_model'); 
    $query = $this->foo_model->validate(); 

    if($query) 
    { 
     $data = array(
      'email' => $this->input->post('email'), 
          'password' => $this->input->post('password'), 
      'is_logged_in' => true 
     ); 
     $this->session->set_userdata($data); 
     redirect('foodash'); 
    } 
    else 
    { 
     $this->index(); // login page 
    } 
} 

從富模式:

function validate() 
{ 
    $this->db->where('email', $this->input->post('email')); 
    $this->db->where('password', $this->input->post('password')); 

    $query = $this->db->get('footable'); 

    if($query->num_rows == 1) 
    { 
     return true; 
    }   
} 

}

想通了: 我的掩蔽我的密碼字段這樣使用jquery輸入文本時不可見。我不得不改變我的密碼字段的名稱 - 一旦我在模型中改變它,一切都很完美。

回答

1

想通了:

我使用jquery,這樣輸入的時候文本是不可見的遮蔽我的密碼字段。我不得不改變我的密碼字段的名稱 - 一旦我在模型中改變它,一切都很完美。

0

在您的IF聲明後,嘗試在您的validate()函數中返回false

也可以嘗試不同的語法:

$query = $this->db->get_where('footable', array(
    'email' => $this->input->post('email'), 
    'password' => $this->input->post('password') 
)); 
+0

使用此語法或在IF語句後使用false不會更改。仍然可以使用無密碼或任何密碼進行登錄。 – chowwy 2012-01-01 23:14:52

0

密碼驗證對數據庫,但validate()返回值是不確定的,當電子郵件或密碼錯誤。這可能會導致不可預知的結果。我建議:

function validate() 
{ 
    $this->db->where('email', $this->input->post('email')); 
    $this->db->where('password', $this->input->post('password')); 

    $query = $this->db->get('footable'); 

    return ($query->num_rows() == 1); 
} 
+0

與我的代碼相同的結果;電子郵件驗證,任何密碼(或無密碼)被接受。 – chowwy 2012-01-01 23:17:08

+0

In($ query-> num_rows == 1)括號丟失,它必須是($ query-> num_rows()== 1) – CodeDownZero 2012-01-02 02:29:14

+0

我看到您的更新;嘗試了你建議的語法w/num_rows(),我仍然可以用任何密碼或沒有密碼登錄。電子郵件正在驗證,但沒有密碼。 – chowwy 2012-01-02 02:38:09