Welcome Guest, Not a member yet? Register   Sign In
help with login
#1

[eluser]dadamssg[/eluser]
So im trying to validate a simple login form. I'm trying to check if the username and password were found in my database. I don't know how to grab the cleaned password into my username_check function though. How do i assign that?

my controller
Code:
<?php

class Login extends Controller {

    function Login()
    {
        parent::Controller();
        $this->load->helper('url');
        $this->load->helper('form');
        
    }

    function index()
    {
        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
        
        $this->form_validation->set_rules('username', 'Username', 'trim|required|callback_username_check|xss_clean');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean');
        
        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('login_view');
        }
        else
        {
            $this->load->view('login_view');
        }
        
        
        function username_check($user, $pass)
        {
            $query = $this->db->query("SELECT loginName,active FROM Member WHERE loginName='$user'
                                AND password=md5('$pass')");
                if($query->result()->num_rows() > 0)
                {
                return TRUE;
                }
                else
                {
                return FALSE;
                }
        
        }
    
    
}

?>
and my login_view
Code:
<?php

echo validation_errors();

echo form_open('login');
?>
<p>&lt;input type='text' name='username' /&gt;&lt;/p>
<p>&lt;input type='password' name='password' /&gt;&lt;/p>
<p>&lt;input type='submit' value='Submit' /&gt;&lt;/p>
&lt;/form&gt;
#2

[eluser]Sean Gates[/eluser]
Unfortunately you only get the field value, in your case the username, passed with the callback when using validation.

From the docs:

Quote:Note: You can also use any native PHP functions that permit one parameter.

Therefore, you can only have one parameter, not two.

You'll need to move the query logic into the index() function and check for the username/password credentials within the validation success block.
#3

[eluser]Nakp[/eluser]
this is not true at all... you can pass another value using the []

just like "matches[field]"

its just that I can't find out how you use the field name and not a string, just like matches does
#4

[eluser]Nakp[/eluser]
actually I did hehehehe


Code:
function v ($field1, $field2){
  $field2 = $this->input->post($field2);

  //al the extra code here
}

so you can use it in your validation rules like 'callback_v[pass]' so you can match the user with that pass Tongue




Theme © iAndrew 2016 - Forum software by © MyBB