PHPackages                             uthmandev/swift2fa - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. uthmandev/swift2fa

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

uthmandev/swift2fa
==================

A secure and easy way to implement Two-Factor Authentication (2FA) with PHP. This library provides an easy-to-use solution for integrating 2FA into your applications, including QR code generation, token verification, and secret key management.

v1.0.2(1y ago)521MITPHPPHP ^7.4 || ^8.0

Since Nov 25Pushed 1y ago1 watchersCompare

[ Source](https://github.com/codetesla51/swift2FA)[ Packagist](https://packagist.org/packages/uthmandev/swift2fa)[ Docs](https://github.com/codetesla51/swift2FA)[ RSS](/packages/uthmandev-swift2fa/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (4)Used By (0)

SWIFT2FA
========

[](#swift2fa)

**Easy and Secure 2-Factor Authentication**

[![Latest Release](https://camo.githubusercontent.com/1a0bc510524b95ecb4d37b82d75891ae570e4ca0a7bbccc3e1931f53df8ef9d9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f636f64657465736c6135312f7377696674324641)](https://github.com/codetesla51/swift2FA/releases)[![Tests Passed](https://camo.githubusercontent.com/7531e5ec825c23e18bfdd6db703fa0540ef47d3eb05bf8171a085942422e20c2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f74657374732d7061737365642d627269676874677265656e)](https://github.com/codetesla51/swift2FA/actions)[![License](https://camo.githubusercontent.com/0fc1109b092f2f3c73f4801207b38b2db51d37cd14352ba4e667468f72a84e18/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f636f64657465736c6135312f7377696674324641)](https://github.com/codetesla51/swift2FA/blob/main/LICENSE)

Overview
--------

[](#overview)

**Swift2FA** is a secure and easy-to-use PHP library for implementing two-factor authentication. It supports various authentication methods, including:

- Authenticator apps (Google Authenticator and others)
- Email authentication via SMTP with PHPMailer
- SMS-based authentication using services like Twilio

### Key Features

[](#key-features)

- Simple integration process
- High-security standards
- Multiple authentication methods
- Built-in encryption for secret keys
- QR code generation
- Flexible time-step settings
- Email and SMS delivery options

Installation
------------

[](#installation)

```
composer require uthmandev/swift2fa
```

Usage Guide
-----------

[](#usage-guide)

### Basic Setup

[](#basic-setup)

```
use Swift2FA\Swift2FA;

$swift2fa = new Swift2FA();
```

### Key Management

[](#key-management)

1. **Encrypting Keys**

```
// Generate and encrypt a new secret key
$encryptedKey = $swift2fa->encryptKey();
```

2. **Decrypting Keys**

```
// Decrypt a stored encrypted key
$decryptedKey = $swift2fa->decryptKey($encryptedKey);
```

### TOTP Operations

[](#totp-operations)

1. **Generating TOTP**

```
// Generate a time-based one-time password
$totpCode = $swift2fa->generateTOTP($secret, $timeStep = 30, $codeLength = 6);
```

2. **Validating TOTP**

```
// Validate a user-provided TOTP code
$isValid = $swift2fa->TOTPValidate($userInput, $secret);
```

### QR Code Generation

[](#qr-code-generation)

```
// Generate a QR code for authenticator apps
$qrCode = $swift2fa->generateQR($userEmail, $decryptedSecret);
```

### Authentication Link Generation

[](#authentication-link-generation)

```
// Generate an otpauth:// link
$authLink = $swift2fa->generatelink($userEmail, $decryptedSecret);
```

### Sending Authentication Codes

[](#sending-authentication-codes)

1. **Via Email**

```
// Send TOTP via email
$swift2fa->Mail(
    mailType: 'SMTP',
    email: 'user@example.com',
    message: 'Your authentication code is: ' . $totpCode,
    name: 'User Name',
    subject: 'Authentication Code'
);
```

2. **Via SMS**

```
// Send TOTP via SMS
$swift2fa->SMS(
    phoneNumber: '+1234567890',
    messageBody: 'Your authentication code is: ' . $totpCode,
    name: 'User Name'
);
```

Configuration
-------------

[](#configuration)

### Environment Variables

[](#environment-variables)

Create a `.env` file with the following configurations:

```
# General Settings
APP_NAME=your_app_name
ENCRYPTION_KEY=your_secure_encryption_key

# Email (SMTP) Settings
HOST=smtp.gmail.com
USER_NAME=your_email@gmail.com
PASSWORD=your_gmail_app_password
PORT=465
SMTP_SECURE=ssl

# SMS (Twilio) Settings
TWILIO_SID=your_twilio_sid
TWILIO_AUTH_TOKEN=your_twilio_auth_token
TWILIO_PHONE_NUMBER=your_twilio_phone_number
```

Important Notes
---------------

[](#important-notes)

1. **Security**

    - Store encryption keys securely
    - Restrict access to environment files
    - Use HTTPS for all authentication operations
2. **TOTP Validation**

    - Standard time step is 30 seconds
    - Email TOTP might require longer time steps (e.g., 120 seconds)
    - QR codes should be the primary method for adding TOTP to authenticator apps
3. **Authentication Links**

    - `otpauth://` links won't work in browsers
    - Use QR codes for adding to authenticator apps

Contributing
------------

[](#contributing)

Contributions are welcome! To contribute:

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

Contact
-------

[](#contact)

- **Developer**: Uthman Oladele
- **Website**: [dev-utman.vercel.app](https://dev-utman.vercel.app)
- **Email**:

---

If you find this project useful, please consider giving it a ⭐ star on GitHub!

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance44

Moderate activity, may be stable

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~6 days

Total

3

Last Release

527d ago

PHP version history (2 changes)v1.0.1PHP ^8.0

v1.0.2PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/b641be61076756388d48c0d8c5bf8e638e389e64ecb163fb6a76b30643985322?d=identicon)[uthman dev](/maintainers/uthman%20dev)

---

Top Contributors

[![codetesla51](https://avatars.githubusercontent.com/u/149274873?v=4)](https://github.com/codetesla51 "codetesla51 (43 commits)")

---

Tags

phpqr codesecurityAuthentication2faTwo Factor AuthenticationToken verification

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/uthmandev-swift2fa/health.svg)

```
[![Health](https://phpackages.com/badges/uthmandev-swift2fa/health.svg)](https://phpackages.com/packages/uthmandev-swift2fa)
```

###  Alternatives

[pragmarx/google2fa

A One Time Password Authentication package, compatible with Google Authenticator.

2.0k82.4M164](/packages/pragmarx-google2fa)[pragmarx/google2fa-qrcode

QR Code package for Google2FA

12124.6M37](/packages/pragmarx-google2fa-qrcode)[ellaisys/aws-cognito

AWS Cognito package that allows Auth and other related features using the AWS SDK for PHP

120220.7k1](/packages/ellaisys-aws-cognito)[remotemerge/totp-php

Lightweight, fast, and secure TOTP (2FA) authentication library for PHP — battle tested, dependency free, and ready for enterprise integration.

2010.2k](/packages/remotemerge-totp-php)[jiripudil/otp

Library that generates and verifies one-time passwords.

2825.4k1](/packages/jiripudil-otp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
