An open API service indexing awesome lists of open source software.

https://github.com/imimofficial/2factorloginforwp

Secure OTP-based login & signup for WordPress using 2Factor.in. Modern, customizable, and production-ready plugin.
https://github.com/imimofficial/2factorloginforwp

login otp plugin wordpress

Last synced: 10 months ago
JSON representation

Secure OTP-based login & signup for WordPress using 2Factor.in. Modern, customizable, and production-ready plugin.

Awesome Lists containing this project

README

          


2Factor Login for WP

2Factor Login for WP


Modern, secure OTP-based login & signup for WordPress

WordPress.org โ€ข GitHub







---

## โœจ Features
- ๐Ÿ” **OTP-based Authentication**: Secure login/signup with phone and OTP (no passwords needed)
- ๐Ÿ”„ **WordPress Integration**: Seamless user creation, login, and onboarding
- ๐Ÿ‘ค **User Role Selection**: Assign any role (default: subscriber) to new users, with admin warning for privileged roles
- ๐Ÿ“ฒ **2Factor API**: Uses your 2Factor.in API key for SMS OTP delivery
- ๐Ÿ“ **Dynamic Onboarding**: Collect email/name after OTP or both (admin configurable)
- ๐ŸŒ **Country Code Dropdown**: User can select country code (or use default)
- ๐Ÿ•ต๏ธโ€โ™‚๏ธ **Privacy-Friendly Usernames**: Truncated phone + random code or full phone (admin option)
- โš™๏ธ **Admin Settings**: 15+ configurable options, all in a modern tabbed UI
- ๐ŸŽจ **Custom Redirect & CSS**: Set redirect after login and inject custom styles
- ๐Ÿ—‚ **User Profile Integration**: Onboarding data (phone, name, email) visible/editable in admin
- ๐Ÿ’Ž **Modern UI**: Responsive, accessible, and minimal design
- ๐Ÿ›ก **Security**: Rate limiting, brute force protection, OTP expiry, validation, and enumeration protection
- ๐Ÿšซ **No test/debug code**: Production-ready, no sensitive data exposed

---

## โšก Quick Start
1. **Upload or clone** to `/wp-content/plugins/2factor-login-for-wp/`
2. **Activate** in your WordPress admin
3. **Configure** via Settings โ†’ 2Factor Login
4. **Add** `[twofactor_login]` shortcode to any page/post

---

## ๐Ÿ–ผ Screenshots

| Screenshot | Preview |
|------------|---------|
| Login Form | ![](https://raw.githubusercontent.com/iMiMofficial/2FactorLoginForWP/main/assets/img/2factor-screenshot-front-end.png) |
| Admin API Settings | ![](https://raw.githubusercontent.com/iMiMofficial/2FactorLoginForWP/main/assets/img/2factor-screenshot-admin-api-settings.png) |
| Admin Customize | ![](https://raw.githubusercontent.com/iMiMofficial/2FactorLoginForWP/main/assets/img/2factor-screenshot-admin-customize.png) |
| Admin Shortcode | ![](https://raw.githubusercontent.com/iMiMofficial/2FactorLoginForWP/main/assets/img/2factor-screenshot-admin-shortcode.png) |
| Admin Advanced | ![](https://raw.githubusercontent.com/iMiMofficial/2FactorLoginForWP/main/assets/img/2factor-screenshot-admin-advanced.png) |
---

## โš™๏ธ Admin Settings
- **2Factor API Key**: Your API key from [2Factor.in](https://2factor.in)
- **OTP Length**: 4-8 digits
- **OTP Expiry**: 1-15 minutes
- **Allow Country Code Selection**: User can pick country (or use default)
- **Default Country Code**: e.g. +91
- **Require Email/Name**: Toggle onboarding fields
- **When to Collect Fields**: After OTP or Both (before/after)
- **Primary Button Color**: UI customization
- **User Role**: Any WordPress role (with warning for "Administrator")
- **Username Generation**: Truncated (privacy-friendly) or full phone number
- **Redirect URL**: Custom after login
- **Custom CSS**: Style injection
- **Dark Mode, Animations, Accessibility**: All UI is accessible and customizable

---

## ๐Ÿ“ Usage
- Add `[twofactor_login]` shortcode to any page/post for the OTP login/signup form
- The form will show phone (+91 pre-filled or country dropdown), and onboarding fields as per settings
- All actions are AJAX-based, no reloads
- New users are created and logged in automatically
- Existing users log in with OTP

---

## ๐Ÿ‘ค User Profile (Admin)
- Onboarding data (phone, name, email) is visible and editable in the user profile in admin
- Admins can update user phone, name, and email from the profile page

---

## ๐Ÿ”’ Security & Best Practices
- โฑ **Rate Limiting**: 1 OTP per minute per phone
- ๐Ÿšซ **Brute Force Protection**: 3 attempts per OTP, plus IP-based lockout (5 minutes after 3 failed attempts)
- โณ **OTP Expiry**: Configurable (default 5 min)
- ๐Ÿ’พ **OTP Storage**: Transient with DB fallback for reliability
- ๐Ÿงน **Validation**: All fields validated and sanitized
- ๐Ÿ›ก **Nonce Verification**: All AJAX and form actions are nonce-protected
- ๐Ÿงผ **Output Escaping**: All output is properly escaped
- ๐Ÿ›ก **SQL Injection Safe**: All queries use `$wpdb->prepare()` and `esc_sql()`
- ๐Ÿ•ต๏ธโ€โ™‚๏ธ **User/Email Enumeration Protection**: Generic error messages for onboarding and user check
- ๐Ÿ“ **No direct file operations**: Uses WP_Filesystem
- ๐Ÿšซ **No debug/test code in production**
- ๐Ÿšซ **No direct access to plugin files**
- ๐Ÿงน **No unnecessary files in release**

---

## ๐Ÿ’ก FAQ

Does it support both login and signup?
Yes! If the phone exists, user logs in. If not, a new user is created.

What if onboarding is disabled?
Username and email are auto-generated from the phone number.

What about passwords?
Passwords are randomly generated and not shown to the user. Users log in with OTP.

Can users set a password later?
Yes, via the default WordPress "Lost your password?" link or admin profile.

Can I use this for WooCommerce or membership sites?
Yes, it works with any plugin that uses standard WordPress user accounts.

Is it compatible with caching plugins?
Yes, OTPs are stored in transients with DB fallback for reliability.

Is it GDPR compliant?
No personal data is sent to 2Factor.in except the phone number for OTP delivery. All data is stored in your WordPress site.

---

## ๐Ÿค Contributing
Pull requests, issues, and suggestions are welcome! For major changes, please open an issue first to discuss what you would like to change.

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

---

## ๐Ÿ™‹โ€โ™‚๏ธ Author & Support


Md Mim Akhtar

imimofficial.com

@iMiMofficial โ€ข GitHub

Patreon โ€ข BuyMeACoffee โ€ข PayPal

---

## ๐Ÿ† Credits
- **Plugin Author:** Md Mim Akhtar
- **Unofficial:** Not affiliated with 2Factor.in

---

## ๐Ÿ“œ License
GPL v2 or later

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, see https://www.gnu.org/licenses/gpl-2.0.html

---

## ๐Ÿ“… Changelog
### 1.0.0
- Initial public release: production-ready, all-in-one plugin