How Can I reset password using the user name instead email addres?

38 views Asked by At

I need to send the email to a specific user, the problem is that the system is designed so that many users can have the same email address, then the problem arises when I use the laravel password reset system, laravel finds the first user who has the email sent by the user I first tried adding a column to the password reset tokens table that contains the username that you want to reset the password.

  public function sendRecoveryToken(Request $request)
  {
      $user = User::where('user', $request->username)->select(['email'])->first();
      $status = Password::sendResetLink(['email' => $user->email);
      DB::table('password_reset_tokens')->where('email', $user->email)->update(['user' => $user->userName]);
      return $status === Password::RESET_LINK_SENT
          ? back()->with(['state' => __($state)])
          : back()->withErrors(['email' => __($status)]);
  }

this sends a url with a token but with the first user for example I have 2 users with the same email

enter image description here if xfeest wants to reset your password, the URL shows the user Jesse50

enter image description here so how can I do it? :(

PS: Now it seems bad to me that many users have the same email but the customer wants to

0

There are 0 answers