Question

I got a question regarding updating a users info using Sentry in Laravel.

I got this in my controller:

public function update()
{
    try{
        $user = $this->sentry->getUser();

        $user->username     = $this->input->get('username');
        $user->first_name   = $this->input->get('first_name');
        $user->last_name    = $this->input->get('last_name');
        $user->email        = $this->input->get('email');
        $user->description  = $this->input->get('description');

        if (!$this->hash->check($this->input->get('password'), $user->password))
        {
            $user->password = $user->password;
        } else {
            $user->password = $this->input->get('password');
        }

        if($user->save())
        {
            return $this->redirect->to('admin');
        } else {
            return $this->redirect->to('admin/'.$user->username.'/');
        }
    }
    catch (\Exception $e)
    {
        return $this->redirect->to('user/'.$user->username.'/profile/edit')->withErrors(array('login'=> $e->getMessage()));
    }
}

which will be processed when submitting the form. However, if i don't fill in a password in the input field, but update something else of the users info and submit the form. It also takes the 'empty' password field, and makes something entirely different from it and because of that i can't login anymore using the original password.

I know there is something wrong at the hash->check part, but what? I don't know. Help would be appreciated.

EDIT: I'm trying to check, if the password field is filled in or not, if it is not filled in, leave the password as it is, if it is filled in, check if its different from the current password, if its different, change it, else leave it as it is

Was it helpful?

Solution

change

    if (!$this->hash->check($this->input->get('password'), $user->password))
    {
        $user->password = $user->password;
    } else {
        $user->password = $this->input->get('password');
    }

to

    if ($this->input->get('password'))
    {
        $user->password = $this->input->get('password');
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top