| title | emoji | colorFrom | colorTo | sdk | pinned |
|---|---|---|---|---|---|
OTP Backend |
π |
blue |
purple |
docker |
false |
A Flask-based REST API that sends OTPs (One-Time Passwords) via email. The API accepts a mobile number, looks up the associated email from a database, generates a 6-digit OTP, and sends it via Resend API.
- Mobile number to email lookup
- 6-digit OTP generation
- Email delivery via Resend API
- CORS enabled for frontend integration
- Production-ready with Gunicorn
- Deployable to Render.com
- Python 3.10+
- Resend API account (free tier available)
- Git and GitHub account
- Render.com account (for deployment)
git clone https://github.com/Pranav77722/otp.git
cd otppip install -r requirements.txt- Sign up at resend.com
- Go to API Keys
- Click "Create API Key"
- Name:
OTP Backend - Permission: Full Access
- Copy the API key (starts with
re_...)
Create a .env file:
cp .env.example .envEdit .env and add your Resend API key:
RESEND_API_KEY=re_your_actual_api_key_here
SENDER_EMAIL=onboarding@resend.dev
python app.pyServer will start at http://localhost:5000
Test the API using PowerShell:
$body = @{
mobile = "9657329173"
} | ConvertTo-Json
Invoke-RestMethod -Uri "http://localhost:5000/send-otp" -Method Post -Body $body -ContentType "application/json"Or using cURL:
curl -X POST http://localhost:5000/send-otp \
-H "Content-Type: application/json" \
-d '{"mobile":"9657329173"}'Expected response:
{
"success": true,
"email": "ap8548328@gmail.com",
"mobile": "9657329173",
"message": "OTP sent"
}git add .
git commit -m "Deploy OTP backend"
git push origin main- Go to Render Dashboard
- Click "New +" β "Web Service"
- Connect your GitHub repository
- Configure:
- Name:
otp-backend - Region: Choose closest to you
- Branch:
main - Runtime:
Python 3 - Build Command:
pip install -r requirements.txt - Start Command:
gunicorn app:app
- Name:
In Render Settings β Environment:
- Click "Add Environment Variable"
- Add:
- Key:
RESEND_API_KEY - Value: Your Resend API key (from step 3 above)
- Key:
- Click "Save Changes"
Render will automatically deploy your app!
Your API will be available at: https://your-service-name.onrender.com
Test it:
$body = @{
mobile = "9657329173"
} | ConvertTo-Json
Invoke-RestMethod -Uri "https://your-service-name.onrender.com/send-otp" -Method Post -Body $body -ContentType "application/json"Request:
{
"mobile": "9657329173"
}Success Response (200):
{
"success": true,
"email": "ap8548328@gmail.com",
"mobile": "9657329173",
"message": "OTP sent"
}Error Responses:
400 - Invalid Request
{
"success": false,
"message": "Mobile number is required"
}404 - Mobile Not Found
{
"success": false,
"message": "Mobile number not registered"
}500 - Server Error
{
"success": false,
"message": "Failed to send email: ..."
}Current users in db.py:
| Mobile Number | |
|---|---|
| 9657329173 | ap8548328@gmail.com |
| 9699883753 | adi.akolkar12@gmail.com |
To add more users, edit db.py:
USERS = {
"9657329173": "ap8548328@gmail.com",
"9699883753": "adi.akolkar12@gmail.com",
"1234567890": "newuser@example.com" # Add new entry
}By default, emails are sent from onboarding@resend.dev.
To use a custom sender:
- Own a domain (e.g.,
yourdomain.com) - Verify it in Resend dashboard
- Add environment variable:
SENDER_EMAIL=noreply@yourdomain.com
- Do NOT commit
.envto GitHub (it's in.gitignore) - Free Resend tier: 3,000 emails/month, 100/day
- Render free tier: May spin down after inactivity (30 sec startup)
- For production, consider upgrading to paid tiers
otp/
βββ app.py # Main Flask application
βββ db.py # User database (mobile β email)
βββ email_service.py # Resend email integration
βββ otp_service.py # OTP generation logic
βββ firebase_init.py # Firebase Admin SDK setup (optional)
βββ requirements.txt # Python dependencies
βββ Procfile # Render/Heroku configuration
βββ Dockerfile # Docker configuration
βββ runtime.txt # Python version
βββ .env.example # Environment template
βββ README.md # This file
Pull requests are welcome! For major changes, please open an issue first.
MIT License
For issues or questions:
- GitHub Issues: Create an issue
- Email: Contact repository owner
Made with β€οΈ using Flask and Resend