Welcome Guest, Not a member yet? Register   Sign In
[help]School Project Here
#21

[eluser]davidbehler[/eluser]
Not talking about your project in general, just the login/auth part. It's really hard to help you at all if you provide non of the requested info. I can't just run around and guess what you might have done or might not have done.

Provide the code or I can't help you.
#22

[eluser]miwrath[/eluser]
im sorry dude...here it is...

my model

Code:
<?php
class User_model extends Model {
    
    function User_model()
    {
        parent::Model();
    }
    
    function check_login($username, $password)
    {
        $shal_password = sha1($password);
              
        $query_str = "SELECT * FROM users WHERE username = ? and password = ?";
        
        $result = $this->db->query($query_str, array($username, $shal_password));
        
      
        
        if ($result->num_rows() == 1)
        {
            return $result->row(0)->teach_id;
        }
        else
        {
            return false;
        }
      
        
    }
    
    
    
}


?>

CONTROLLER

Code:
<?php
class Registrar extends Controller {

    function Registrar()
    {
        parent::Controller();    
    }
    
    function index()
    {
            $this->login();
                    
    }
        
        function secondary_page()
        {
            
        }
        
        
        function main_page()
        {
            if ($this->session->userdata('logged_in'))
            {
                echo 'you are now logged in' ;
                
            }          
            
            else
            {
                redirect('index.php/user/login');
            }
            
          
            
            
        }
        
        function login()
        {
            $this->form_validation->set_rules('username', 'Username', 'trim|required|max_length[50]|xss_clean');  
            $this->form_validation->set_rules('password', 'Password', 'trim|required|max_length[50]|xss_clean');  
                                
                    
            if ($this->form_validation->run() == FALSE)
            {
                $this->load->view('view_registrar');
            }
            else
            {
                echo 'You are great!';
                //process the input and login the user;
                
                /*$sername = $_POST('username');
                $username = $this->input->post('username');
                $password = $_POST('password');
                $password = $this->input->post('password');
                */
               extract($_POST);
            
               $teach_id = $this->User_model->check_login($username, $password);
              
               if (! $teach_id)
               {
                   //login failed error
                  
                   $this->session->set_flashdata('login_error', TRUE);
                  
                   redirect('index.php');
               }
               else
               {
                   //login

                   $this->session->set_userdata(array(
                                           'logged_in' => TRUE,
                                           'teach_id' => $teach_id
                                                     ));
                  
                   redirect('main_page');
                  
               }
                
            }
            
            // echo $this->db->last_query();
            //exit();  
                  
        }
        
}

?>

VIEWS


Code:
<html>
<head>
<title>Welcome</title>

<style type="text/css">

body {
background-color: #fff;
margin: 40px;
font-family: Lucida Grande, Verdana, Sans-serif;
font-size: 14px;
color: #4F5155;
}

a {
color: #003399;
background-color: transparent;
font-weight: normal;
}

h1 {
color: #444;
background-color: transparent;
border-bottom: 1px solid #D0D0D0;
font-size: 16px;
font-weight: bold;
margin: 24px 0 2px 0;
padding: 5px 0 6px 0;
}

code {
font-family: Monaco, Verdana, Sans-serif;
font-size: 12px;
background-color: #f9f9f9;
border: 1px solid #D0D0D0;
color: #002166;
display: block;
margin: 14px 0 14px 0;
padding: 12px 10px 12px 10px;
}

ul {
list-style: none;
}

ul list{
    margin-top:0;
}

div#login_form{
    width:350px;
    margin: 0px auto;
    border:1px solid #acacac;
    padding:10px;
}


</style>
</head>
<body>

<div id="login_form">
    <h1>Please login.</h1>
    <p>Use the form to login...</p>
    
&lt;?php echo form_open(base_url() . 'index.php/registrar/login'); ?&gt;  
    
    <ul>
    <li>
        <label>Username</label>
        <div>
            &lt;?php echo form_input(array ('id'=> 'username', 'name'=> 'username'));?&gt;        
        </div>
    </li>
    <li>
                <label>Password</label>
        <div>
            &lt;?php echo form_password(array ('id'=> 'password', 'name'=> 'password'));?&gt;        
        </div>    
    </li>
        
    <li>
        &lt;?php
            if ($this->session->flashdata('login_error'))
            {
                echo 'You entered incorrect username or password';
            }
            
            echo validation_errors(); ?&gt;</li>
    
        &lt;?php echo form_submit(array('name' => 'submit'), 'Login'); ?&gt;
        
    </ul>

&lt;?php echo form_close(); ?&gt;
    
</div>


&lt;/body&gt;
&lt;/html&gt;
#23

[eluser]miwrath[/eluser]
i think the login checking goes really bad...
#24

[eluser]davidbehler[/eluser]
This doesn't make much sense. There is no way that the query string you posted before
Code:
UPDATE `users` SET `last_activity` = 1313725176, `user_data` = '' WHERE `session_id` = 'ad0587c01a8c6bb737f410c742c6d0b8'
was generated by your model
Code:
$query_str = "SELECT * FROM users WHERE username = ? and password = ?";
$result = $this->db->query($query_str, array($username, $shal_password));

Try this code in your model instead of the two lines I quoted:
Code:
echo 'username: '.$username.'<br/>';
echo 'password: '.$password.'<br/>';
echo 'password hash: '.$sha1_password.'<br/>';
$query_str = "SELECT * FROM users WHERE username = ? and password = ?";
$result = $this->db->query($query_str, array($username, $shal_password));
echo 'query: '.$this->db->last_query();
exit();
and please tell me what the password hash in your database looks like.
#25

[eluser]miwrath[/eluser]
wait dude...
problem solve...i change the code in your suggestion and this message goes out...
but the user auth...doesnt working...i can login using any names and pw...

This is on the controller php file.


Code:
&lt;?php
class Registrar extends Controller {

    function Registrar()
    {
        parent::Controller();    
    }
    
    function index()
    {
            $this->login();
                    
    }
        
        function secondary_page()
        {
            
        }
        
        
        function main_page()
        {
            if ($this->session->userdata('logged_in'))
            {
                echo 'you are now logged in' ;
                
            }          
            
            else
            {
                redirect('index.php/user/login');
            }
            
          
            
            
        }
        
        function login()
        {
            $this->form_validation->set_rules('username', 'Username', 'trim|required|max_length[50]|xss_clean');  
            $this->form_validation->set_rules('password', 'Password', 'trim|required|max_length[50]|xss_clean');  
                                
                    
            if ($this->form_validation->run() == FALSE)
            {
                $this->load->view('view_registrar');
            }
            else
            {
                echo 'You are great!';
                //process the input and login the user;
                
                $username = $_POST('username');
                $username = $this->input->post('username');
                $password = $_POST('password');
                $password = $this->input->post('password');
                
               //extract($_POST);
            
               $teach_id = $this->User_model->check_login($username, $password);
              
               if (! $teach_id)
               {
                   //login failed error
                  
                   $this->session->set_flashdata('login_error', TRUE);
                  
                   redirect('index.php');
               }
               else
               {
                   //login

                   $this->session->set_userdata(array(
                                           'logged_in' => TRUE,
                                           'teach_id' => $teach_id
                                                     ));
                  
                   redirect('main_page');
                  
               }
                
            }
            
            // echo $this->db->last_query();
            //exit();  
                  
        }
        
}

?&gt;

Code:
You are great!
( ! ) Fatal error: Function name must be a string in D:\wamp\www\registrar\system\application\controllers\registrar.php on line 54
Call Stack
#    Time    Memory    Function    Location
1    0.0011    380104    {main}( )    ..\index.php:0
2    0.0065    429720    require_once( 'D:\wamp\www\registrar\system\codeigniter\CodeIgniter.php' )    ..\index.php:115
3    0.1212    2986056    call_user_func_array ( )    ..\CodeIgniter.php:236
4    0.1212    2986104    Registrar->login( )    ..\CodeIgniter.php:0
#26

[eluser]davidbehler[/eluser]
Oh for crying out loud, just do what I told you and you'll get the query that's run to check if the entered user exists.
#27

[eluser]miwrath[/eluser]
help...i still can input any names and password i think the checking is still a crap...

:-S



Code:
if ($this->form_validation->run() == FALSE)
            {
                $this->load->view('view_registrar');
            }
            else
            {
                echo 'You are great!';
                //process the input and login the user;
                
line 54--------&gt; $username = $_POST('username');
                $username = $this->input->post('username');
                $password = $_POST('password');
                $password = $this->input->post('password');
                
               //extract($_POST);
            
               $teach_id = $this->User_model->check_login($username, $password);
              
               if (! $teach_id)
               {
                   //login failed error
                  
                   $this->session->set_flashdata('login_error', TRUE);
                  
                   redirect('index.php');
Fatal error: Function name must be a string in D:\wamp\www\registrar\system\application\controllers\registrar.php on line 54
#28

[eluser]davidbehler[/eluser]
What exactly are you doing? Do you actually read what I write or just randomly copy my examples? I'm talking about this post: http://ellislab.com/forums/viewthread/19...20/#927232

And the above error is propably caused by the [ quote] and [/ quote] you got there right before and after
Code:
$username = $_POST('username');
#29

[eluser]miwrath[/eluser]
here it is..

the one example is 'mark' and hes password is 'mcc'. this is the one im trying to use to login.

http://h1.ripway.com/mirat/a.JPG
#30

[eluser]davidbehler[/eluser]
That url doesn't work...




Theme © iAndrew 2016 - Forum software by © MyBB