Download the PHP package andydefer/laravel-totp without Composer

On this page you can find all versions of the php package andydefer/laravel-totp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-totp

Laravel TOTP

Package de double authentification TOTP (RFC 6238) pour Laravel avec support polymorphique

Latest Version Total Downloads PHP Version License

Un package Laravel pour la double authentification (2FA) avec TOTP (RFC 6238), support polymorphique, codes de récupération et génération de QR Code.


📋 Table des matières


✨ Fonctionnalités


🚀 Prérequis


📦 Installation

Installez le package via Composer :

Publier les migrations

Exécuter les migrations


⚙️ Configuration

Le package est automatiquement découvert par Laravel. Aucune configuration supplémentaire n'est requise.

Si vous devez personnaliser le Service Provider, ajoutez-le manuellement dans config/app.php :

Dépendances optionnelles

Pour la génération de QR Code, le package utilise endroid/qr-code. Assurez-vous que l'extension GD est activée :


🏗️ Structure du package

⚠️ Important : Aucune relation dans les modèles consommateurs

Contrairement à d'autres packages, le modèle consommateur (User, Admin, etc.) n'a pas besoin de déclarer de relation. Seul le modèle TotpSecret contient les relations polymorphiques.


📖 Utilisation

Configurer TOTP

Réponse :

Activer TOTP après vérification

Vérifier un code TOTP

Vérifier un code de récupération

Désactiver TOTP

Régénérer les codes de récupération

Vérifier l'état de TOTP


📚 Référence de l'API

TotpService

Méthode Description Retourne Exception
setup(Model $authenticatable) Configurer TOTP (génère secret, QR Code, codes récupération) array{secret, qr_code, qr_code_uri, recovery_codes} -
verifyAndEnable(Model $authenticatable, string $code, int $window = 1) Vérifier le code et activer TOTP bool TotpException
enable(Model $authenticatable, string $secret, array $recoveryCodes) Activer TOTP avec un secret existant TotpSecret -
disable(Model $authenticatable) Désactiver TOTP bool TotpException
verify(Model $authenticatable, string $code, int $window = 1) Vérifier un code TOTP bool TotpException
verifyRecoveryCode(Model $authenticatable, string $code) Vérifier un code de récupération bool TotpException
markAsVerified(Model $authenticatable) Marquer TOTP comme vérifié void -
isEnabled(Model $authenticatable) Vérifier si TOTP est activé bool -
isVerified(Model $authenticatable) Vérifier si TOTP est vérifié bool -
getRemainingRecoveryCodes(Model $authenticatable) Récupérer les codes de récupération restants StringTypedCollection -
regenerateRecoveryCodes(Model $authenticatable) Régénérer les codes de récupération StringTypedCollection -
getSecret(Model $authenticatable) Récupérer le secret ?string -

TotpGenerator

Méthode Description Retourne
generateSecret(int $length = 32) Générer un secret Base32 string
generateCode(string $secret, ?int $timestamp = null, int $digits = 6, int $period = 30) Générer un code TOTP string
generateCodesWithWindow(string $secret, int $digits = 6, int $period = 30, int $window = 1, ?int $timestamp = null) Générer les codes avec fenêtre de tolérance array
generateRecoveryCodes(int $count = 10, int $length = 8) Générer des codes de récupération array
hashRecoveryCodes(array $codes) Hasher les codes de récupération (SHA256) array
verifyRecoveryCode(string $code, array $hashedCodes) Vérifier un code de récupération bool

QrCodeGenerator

Méthode Description Retourne
generate(string $account, string $secret, string $issuer, int $digits = 6, int $period = 30, string $algorithm = 'SHA1') Générer un QR Code PNG string
generateFromUri(string $uri) Générer un QR Code à partir d'une URI string
generateDataUri(string $uri) Générer une Data URI du QR Code string
buildUri(string $account, string $secret, string $issuer, int $digits = 6, int $period = 30, string $algorithm = 'SHA1') Construire l'URI TOTP string

🎯 Value Objects

Le package supporte les Value Objects suivants :

Value Object Description Exemple
TotpSecretVO Secret TOTP avec métadonnées new TotpSecretVO('JBSWY3...', true, [...], $verifiedAt)
DateTimeVO Date/heure new DateTimeVO('2024-01-01 12:00:00')
StrictDataObject Métadonnées typées StrictDataObject::from(['ip' => '127.0.0.1'])

Accesseurs dans le modèle TotpSecret


📝 Structure de la base de données

Structure du champ recovery_codes (JSON)

Les codes de récupération sont hashés en SHA256 avant stockage.


🔧 Exceptions possibles

Exception Message Quand ?
TotpException::totpNotEnabled() TOTP is not enabled for this user. verify() appelé mais TOTP pas activé
TotpException::secretNotFound() TOTP secret not found. verify() appelé mais secret inexistant
TotpException::invalidCode() Invalid TOTP code. Code invalide
TotpException::invalidRecoveryCode() Invalid recovery code. Code de récupération invalide
TotpException::alreadyEnabled() TOTP is already enabled for this user. Activation déjà faite
TotpException::alreadyDisabled() TOTP is already disabled for this user. Désactivation déjà faite
TotpException::maxAttemptsExceeded() Maximum TOTP attempts exceeded. Trop de tentatives
TotpException::setupFailed() TOTP setup failed. Échec de la configuration

👨‍💻 Auteur

Andy Kani


⭐ Support

Si vous trouvez ce package utile, n'hésitez pas à lui donner une ⭐ sur GitHub !


🙏 Remerciements


Construit avec ❤️ pour la communauté Laravel


All versions of laravel-totp with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
laravel/framework Version ^12.0|^13.0|^14.0|^15.0
andydefer/laravel-repository Version ^2.17.38
endroid/qr-code Version ^5.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package andydefer/laravel-totp contains the following files

Loading the files please wait ...