Question

I'm trying to make a new Login/Register System. My users are able to register now but i cant get the information when they try to login

if(Input::exists()){
    if (Token::check(Input::get('token'))){

        $validate = new Validate();
        $validation = $validate->check($_POST, array(
            'username' => array('required' => true),
            'password' => array('required' => true)
        ));

        if($validation->passed()){
            // log user in
            $user = new User();
            $login = $user->login(Input::get('username'), md5('password'));
            if($login){
                echo "succes";
            } else {
                echo '<p>Sorry, logging in failed</p>';
            }

        }else{
            foreach($validation->errors() as $error){
                echo $error, "<br>";
            }
        }
    }
}

This it the code why can't they login? I think it's something with the md5('password'). Because i always get the Error: Sorry, logging in failed. This is the Passed()

public function passed() {
    return $this->_passed;
}

And this is the one for the login()

public function login($username = null, $password = null){      
        $user = $this->find($username);

        if($user){
            if($this->data()->password === Hash::make($password, $this->data()->salt)){
                echo 'OK!';
            }
        }

        return false;
    }
    private function data(){
        return $this->_data;
    }

i used to use salts but it took very long to generate one i i also don't know that either why that is like that i will also make soon an topic about that but for now i want to use MD5 just to make my other functionality.

Was it helpful?

Solution

Looks as though you are using Laravel? or something similar.

Try this instead:

$login = $user->login(Input::get('username'), 'password');

or perhaps you want:

$login = $user->login(Input::get('username'), Input::get('password'));

The login() function seems to be already doing the conversion to hash with Hash::make

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top