🔐 Secure and simple OTP (One-Time Password) generator and verifier with SMS integration.
This repository contains a Java application that generates and verifies OTPs using a MySQL database and sends the OTP to a mobile number via an SMS API.
🌟 Key Features:
- Generate random 6-digit OTPs.
- Verify OTPs with time and date constraints.
- Send OTPs via SMS using an external API.
- Installation
- Usage
- Configuration
- Database Setup
- SMS API Integration
- Demo: Database Table
- Contributing
- License
-
Clone the repository:
git clone https://github.com/your-username/your-repository.git cd your-repository
-
Download the MySQL Connector/J JDBC driver JAR file and add it to your project's classpath.
- MySQL Connector/J: Download Link
-
Compile and run the Java application:
javac Main.java java Main
-
Follow the instructions in the console to input mobile numbers, OTPs, and verify the OTPs.
- Input your mobile number to receive an OTP via SMS.
- Enter the received OTP to verify.
Before running the application, you need to set up the following configurations:
-
JDBC Server Host Link:
- Replace
YOUR_JDBC_SERVER_HOST_LINK
inMain.java
with your MySQL server link.
- Replace
-
Database Credentials:
- Replace
YOUR_USER_NAME
andYOUR_PASSWORD
inMain.java
with your MySQL username and password.
- Replace
-
SMS API Credentials:
- Replace
YOUR_SMS_API_URL/ENDPOINT
andYOUR_SMS_API_KEY
inMain.java
with your API details.
- Replace
-
Create a MySQL database named
otp
. -
Execute the following SQL script to create the
otptable
table:CREATE TABLE otptable ( id INT AUTO_INCREMENT PRIMARY KEY, mobile VARCHAR(11) NOT NULL, code VARCHAR(6) NOT NULL, date DATE NOT NULL, time TIME NOT NULL );
-
Sign up for an SMS API service and obtain your API key.
-
Replace
YOUR_SMS_API_URL/ENDPOINT
andYOUR_SMS_API_KEY
inMain.java
with your API details.
Here's a demo of the otptable
database table:
id | Mobile | Code | Date | Time |
---|---|---|---|---|
1 | 1234567890 | 123456 | 2023-11-27 | 12:34:56 |
2 | 9876543210 | 654321 | 2023-11-26 | 18:45:30 |
Contributions are welcome! Feel free to open issues or submit pull requests.
This project is licensed under the MIT License.