master

laravel/framework

Last updated at: 29/12/2023 09:24

Password.php

TLDR

This file defines the Password class, which is a facade for the PasswordBroker class. It provides methods for managing password reset functionality.

Classes

Password

This class is a facade for the PasswordBroker class, which provides methods for managing password reset functionality. It acts as a proxy to the actual implementation, allowing access to the methods on the underlying PasswordBroker class via static calls.

Some notable methods provided by this class are:

  • broker(string|null $name = null): Returns an instance of the PasswordBroker class. If a name is provided, it returns the named broker instance.
  • getDefaultDriver(): Returns the default driver name for password reset mechanism.
  • setDefaultDriver(string $name): Sets the default driver name for password reset mechanism.
  • sendResetLink(array $credentials, \Closure|null $callback = null): Sends a password reset link to the user with the given credentials. Optionally, a callback function can be provided to handle additional logic after the reset link has been sent.
  • reset(array $credentials, \Closure $callback): Resets the password for a user with the given credentials. The callback function is responsible for updating the user's password.
  • getUser(array $credentials): Retrieves a user instance with the given credentials, if one exists.
  • createToken(\Illuminate\Contracts\Auth\CanResetPassword $user): Generates a password reset token for the given user.
  • deleteToken(\Illuminate\Contracts\Auth\CanResetPassword $user): Deletes the password reset token for the given user.
  • tokenExists(\Illuminate\Contracts\Auth\CanResetPassword $user, string $token): Checks if the given user has a valid token for password reset.
  • getRepository(): Returns an instance of the TokenRepositoryInterface, which is responsible for managing password reset tokens.

Please refer to the PasswordBrokerManager and PasswordBroker classes for more details on the password reset functionality.

<?php

namespace Illuminate\Support\Facades;

use Illuminate\Contracts\Auth\PasswordBroker;

/**
 * @method static \Illuminate\Contracts\Auth\PasswordBroker broker(string|null $name = null)
 * @method static string getDefaultDriver()
 * @method static void setDefaultDriver(string $name)
 * @method static string sendResetLink(array $credentials, \Closure|null $callback = null)
 * @method static mixed reset(array $credentials, \Closure $callback)
 * @method static \Illuminate\Contracts\Auth\CanResetPassword|null getUser(array $credentials)
 * @method static string createToken(\Illuminate\Contracts\Auth\CanResetPassword $user)
 * @method static void deleteToken(\Illuminate\Contracts\Auth\CanResetPassword $user)
 * @method static bool tokenExists(\Illuminate\Contracts\Auth\CanResetPassword $user, string $token)
 * @method static \Illuminate\Auth\Passwords\TokenRepositoryInterface getRepository()
 *
 * @see \Illuminate\Auth\Passwords\PasswordBrokerManager
 * @see \Illuminate\Auth\Passwords\PasswordBroker
 */
class Password extends Facade
{
    /**
     * Constant representing a successfully sent reminder.
     *
     * @var string
     */
    const RESET_LINK_SENT = PasswordBroker::RESET_LINK_SENT;

    /**
     * Constant representing a successfully reset password.
     *
     * @var string
     */
    const PASSWORD_RESET = PasswordBroker::PASSWORD_RESET;

    /**
     * Constant representing the user not found response.
     *
     * @var string
     */
    const INVALID_USER = PasswordBroker::INVALID_USER;

    /**
     * Constant representing an invalid token.
     *
     * @var string
     */
    const INVALID_TOKEN = PasswordBroker::INVALID_TOKEN;

    /**
     * Constant representing a throttled reset attempt.
     *
     * @var string
     */
    const RESET_THROTTLED = PasswordBroker::RESET_THROTTLED;

    /**
     * Get the registered name of the component.
     *
     * @return string
     */
    protected static function getFacadeAccessor()
    {
        return 'auth.password';
    }
}