Forgot Password

If an existing user forgot his password he has the possibility of resetting his password.


In the case of an user forgetting the credentials there is the possibility of resetting them. For resetting the password the user should use the Forgot password? button from the login page. The user must provide the email for the account and after that a link will be sent for resetting the password to the provided mail address.

The App/Http/Livewire/Auth/ForgotPassword.php handles the recovery of the password.

              
                public function show(){

                  $this->validate();

                  $user = User::where('email', $this->email)->first();

                      if($user){

                          $this->notify(new ResetPassword($user->id));

                          return back()->with('status', "Email sent.");

                      } else {
                          return back()->with('email', "Invalid email");
                      }
              }
              
              

The user can access the reset password page by clicking the button found in the email. The link for resetting the password is available for 12 hours and is unique for the user. The user must add the password and confirm the password for his password to be updated.

The App/Http/Livewire/Auth/ResetPassword.php helps the user reset the password.

            
              public function update(){

                $this->validate();

                $existingUser = User::where('email', $this->email)->first();

                if($existingUser && $existingUser->id == $this->urlID) {
                    $existingUser->update([
                        'password' => $this->password
                    ]);
                    redirect('sign-in')->with('status', 'Password changed.');
                } else {
                    return back()->with('email', "Invalid email");
                }

            }