1

I copied an example from the laravel documentation:

public function postResetPassword() { $credentials = array('email' => Input::get('email')); return Password::reset($credentials, function($user, $password) { $user->password = Hash::make($password); $user->save(); return Redirect::to('/'); }); } 

But it seems that returning Redirect::to('/') doesn't work, because instead of home page I get an error which tells that controller method is not found. But if I write the code this way:

 $credentials = array('email' => Input::get('email')); Password::reset($credentials, function($user, $password) { $user->password = Hash::make($password); $user->save(); }); return Redirect::back(); 

It works, though I can't understand how do I get session flash variables (actually I get them).

Another question is where are the rules about password length (6 chars) are written? Can I change them?

2
  • What's your first question again? I will advise you to have a look at Sentry. You just drop it in and it does a lot of this dirty work for you. docs.cartalyst.com/sentry-2/users/reset-password Commented Jul 15, 2013 at 20:03
  • It seems as though the password rules are still hardcoded. Check out this SO answer for a way to change them: stackoverflow.com/q/16762840/1317935 Commented Jul 16, 2013 at 3:51

2 Answers 2

1

To answer why your first code example doesn't work is because if your look at your app/routes.php file you should see something along the lines of Route::get('/', 'HomeController@index');. The part that comes before the @ symbol is the name of your controller while the part after it is the method that is being called in your controller when the route is requested. Make sure that method is defined.

After looking at the following. I think you should put the redirect inside of the closure you give as a return statement.

Then how you retrieve data that has been flashed to the session after redirecting the user you use the following Session::get('key');.

For your last question look at the following documentation.

Example:

$validator = Validator::make( array('email' => Input::get('email'), 'password' => Input::get('password'), 'password_confirm' => Input::get('password_confirm')), array('email' => 'required|unique:users,email|email', 'password' => 'required|min:3|max:20|same:password_confirm') ); 

The second array passed is where you can modify the rules for the validator.

Sign up to request clarification or add additional context in comments.

3 Comments

'/' is the right route. The reason is that when I get an error (lets say user didn't input any password or the email is not exists) Password::reset doesn't go to the anonymous function and returns a redirect to the same URI (I guess). When user entered right values the anonymous function works and returns redirect to '/'. The strange thing for me is that to control redirect when I get validation errors I need to use setTargetUrl for returning redirect (like $redirect = Password::reset(...); $redirect->setTargetUrl('some page where I want to display errors');
About password validation (my second question) - I know how to use validation class, but when I use Password::reset method it checks that password has minimum 6 chars, but where is that setting about 6 chars? Actually I want to change it to 8. If it's in the documentation, my mistake, but I haven't found it yet
@Victor Hopefully the edit I just did helps with your second question.
0

To answer your second question regarding changing the rules for password validation.

The Password facade extends PasswordBroker.php which has this function on line 208:

/** * Set a custom password validator. * * @param \Closure $callback * @return void */ public function validator(Closure $callback) { $this->passwordValidator = $callback; } 

Therefore, to override the default password validator, simply make this call from your controller:

Password::validator(function(){ //validator in here }); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.