Support the ongoing development of Laravel.io →
posted 10 years ago
Authentication

These are my three functions to recover a password. Everything seems right. In my routes, I am passing the {code} back as well. I did a var_dump($user) and nothing returns. My postForgotPassword is right because the email sends fine with the password and activation code. When I click the activation code I get the else on the conditional instead of returning true.

public function getForgotPassword() {
		return View::make('account.forgot');

	}

	public function postForgotPassword() {
		$validator = Validator::make(Input::all(),
			array (
				'email' => 'required|email'
			)
		);

		if($validator->fails()) {
			return Redirect::route('account-forgot-password')
				->withErrors($validator)
				->withInput();
		}else{
			//change password
			$user = User::where('email', '=', Input::get('email'));

			if($user->count()) {
				$user 					= $user->first();

				//Generate new code and password
				$code					= str_random(60);
				$password 				= str_random(10);

				$user->code 			= $code;
				$user->password_temp	= Hash::make($password);

				if($user->save()) {
					Mail::send('emails.auth.forgot', array(
						'link' => URL::route('account-recover', $code),
						'username' => $user->username,
						'password' => $password), 
					function($message) use ($user) {
						$message->to($user->email, $user->username)->subject('Your new password.');
					});

					return Redirect::route('home')
						->with('global', 'We have sent you a new password.');
				}	

		}
	}

		return Redirect::route('account-forgot-password')
			->with('global', 'Could not request new password.');
	}

	public function getRecover($code) {
		$user = User::where('code', '=', $code)
			->where('password_temp', '!=', '');

		if($user->count()) {
			$user = $user->first();

			$user->password 		= $user->password_temp;
			$user->password_temp 	= '';
			$user->code 			= '';
 


			if($user->save()) {
				return Redirect::route('home')
					->with('global', 'Your account has been recovered and you can sign in with your new password.');
			}
		}

		return Redirect::route('home')
			->with('global', 'Could not recover your account.');
                
			
	}

Last updated 2 years ago.
0

I thought you are missing this User::wher('...') and you need this ->get() at the end

Last updated 2 years ago.
0

I tried that and it did not work. I have checked my code several times.

Last updated 2 years ago.
0

Thank you @PFY on the chat, I had a "z" in my view appended to the passed url which in turn was causing the link to fail.

Last updated 2 years ago.
0

If you are looking for simple way to backup then try Ahsay Software. Ahsay Backup software is the best backup solution has it all real-time archiving, unlimited versions of files, fully automatic and it designed for manage service provider to provide online backup service to their users. I'm really happy with it. You can also try this.

0

Steve-45 = spammer!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

swgj19 swgj19 Joined 11 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.