A simple and secure OTP (One-Time Password) Verification System built using core PHP. This project demonstrates how to generate, send, and verify OTPs using session management.
- Generate 6-digit OTP
- Email-based OTP (mock implementation)
- OTP verification system
- Session-based storage
- OTP expiry handling (5 minutes)
- Simple and clean structure (beginner-friendly)
otp-system/
│── index.php # Enter email
│── send_otp.php # Generate & send OTP
│── verify.php # OTP input page
│── check_otp.php # OTP verification logic
│── success.php # Success page
│── config.php # Configuration & session
- User enters email on index.php
- OTP is generated in send_otp.php
- OTP is stored in session
- User enters OTP in verify.php
- OTP is validated in check_otp.php
- If correct → redirected to success page
- Clone the repository:
git clone https://github.com/yogeshkumarsaini/otp-system.git
- Move project to your server directory:
- XAMPP →
htdocs - WAMP →
www
-
Start Apache server
-
Open in browser:
http://localhost/otp-system/
- OTP is currently displayed on screen (for testing)
- No real email is sent in this version
- Session is used instead of database
- Hash OTP before storing (
password_hash) - Limit OTP attempts (e.g., max 3 tries)
- Add CSRF protection
- Use HTTPS
- Store OTP in database instead of session
To send real OTP emails, use:
- PHPMailer (SMTP-based email sending)
You can integrate:
- Fast2SMS API
- Twilio API
Store OTP details in MySQL:
email | otp | expiry | attempts
- User registration
- Login verification
- Password reset
- Two-factor authentication (2FA)