Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Password Change feture not working
  • i am trying to change the password of the user by using the below code

    Auth::forge('simpleauth')->change_password(Input::post('oldpass'), Input::post('newpass'), Input::post('username'));

    but it is not working also i am not able to see the error can provide me with the proper code to change the password in fuelphp 

    please 
  • It throws exceptions if the input is not correct. And returns a boolean if it does. What does it return?
  • You can try this

    if (Input::method() == 'POST')
    {        
                //Put your validation rule
                $val->add('oldpassword', 'Old Password')
                    ->add_rule('required');
                $val->add('newpassword', 'New Password')
                    ->add_rule('required')
                    ->add_rule('min_length', 3)
                    ->add_rule('max_length', 10);
                 
                if ($val->run())
                {
                    try
                    {
                        // change password
                        if(Auth::instance()->change_password(Input::param('oldpassword'), Input::param('newpassword')))
                        {
                            $this->template->set_global('change_password_error', 'Password change');
                        }
                        else
                        {
                            $this->template->set_global('change_password_error', 'Old password was incorrect');
                        }
                    }
                    // catch exceptions from the change_password call
                    catch (SimpleUserUpdateException $e)
                    {
                        $this->template->set_global('change_password_error', $e->getMessage());
                    }
                }
            }


    change_password returns true if the password was changed, or false if the old password was incorrect and it throws SimpleUserUpdateException.

    You can check doc http://fuelphp.com/docs/packages/auth/ormauth/usage.html#/method_change_password
  • the problem is it do not return any think i have try to do this
    $v = Auth::forge('simpleauth')->change_password(Input::post('oldpassword'), Input::post('newpassword'),Input::post('username'));
    echo $v;
    the value of the v is blank
    can to tell what wrong in this
  • change_password() returns a boolean, you can not echo that.

    echo $v ? 'true' : 'false':
  • i have tryed every think on it but still it is not working
    $val = Validation::forge('changepassword');
    $val->add('oldpassword', 'Old Password')
    ->add_rule('required');
    $val->add('newpassword', 'New Password')
    ->add_rule('required')
    ->add_rule('min_length', 3);
    $val->add('retypepass', 'Retype Password')
    ->add_rule('required')
    ->add_rule('match_value', Input::post('newpassword'));

    $val->set_message('required', ':label is required');
    $val->set_message('match_value', 'Password do not match');
    if ($val->run()) {
    // change password
    // $v = Auth::instance()->change_password(Input::post('oldpassword'), Input::post('newpassword'));
    if (Auth::instance()->change_password(Input::param('oldpassword'), Input::param('newpassword'))) {
    $arrayName = array('status' => true);
    $view = json_encode($arrayName);
    } else {
    $arrayName = array('status' => false,
    'validation' => 'oldpassword wrong');
    $view = json_encode($arrayName);
    }
    } else {
    $arrayName = array('status' => false,
    'validation' => $arrayName = array(
    'oldpassword' => $val->error('oldpassword') ? $val->error('oldpassword')->get_message() : null,
    'newpassword' => $val->error('newpassword') ? $val->error('newpassword')->get_message() : null,
    'retypepassword' => $val->error('retypepass') ? $val->error('retypepass')->get_message() : null,
    ),
    );
    $view = json_encode($arrayName);
    }
    }return $view
    and i am get wrong password as return type.. i am entrying corrent password .. plz help
  • The change_password() method catches the underlying exception, so the exact cause is lost.

    Use

    Auth::instance()->update_user(array('old_password' => $old_password, 'password' => $new_password))

    and you'll get a more detailed exception returned.

    Note that this code (both update_user and change_password) requires the user to be logged in. If not, you need to pass the username too.
  • i am getting error saying the old password is invalid but i am very sure that that i am typing the right password. the password which i have enter is 123456
    plz have any solution to this
  • It does:

    if (empty($values['old_password'])
        or $current_values->get('password') != $this->hash_password(trim($values['old_password'])))
    {
        throw new \SimpleUserWrongPassword('Old password is invalid');
    }

    So either you didn't pass the old password (correctly), or it is wrong. I can't see any other option?

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion