-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathotp-generator.py
More file actions
65 lines (50 loc) · 1.74 KB
/
Copy pathotp-generator.py
File metadata and controls
65 lines (50 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# OTP Generator with Time Limit Automatically Send on Email
import random
import time
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
print("🥷 Welcome to Secure Login System")
email = input("📧 Enter your Email: ")
# Generate OTP
otp = random.randint(100000,999999)
expiry_time = time.time() + 120 # OTP valid for 2 minutes(120 seconds)
attempts = 3
# --- Email Part ---
sender_email = "rameshgehlot2210@gmail.com"
sender_password = "wcos fdvg xedf nvvl"
receiver_email = email
msg = MIMEMultipart("alternative")
msg["From"] = sender_email
msg["To"] = receiver_email
msg["Subject"] ="Your OTP!"
html_body = f"""
<html>
<body>
<h2 style="color: red;">Secure System! 🧑💻</h2>
<p><b>Hi! Your OTP To Access Secure System is [{otp}]</b></p>
<p><strong>Valid for 2 Minutes. Don't Share with Anyone</strong></p>
</body>
</html>
"""
msg.attach(MIMEText(html_body, "html"))
with smtplib.SMTP_SSL("smtp.gmail.com", 465) as server:
server.login(sender_email, sender_password)
server.sendmail(sender_email, receiver_email, msg.as_string())
print("\n💬 OTP has been sent to your Email")
# print("(Practice mode OTP:", otp ) # remove in production
# Main loop for OTP verification
while attempts > 0:
user_otp = input("Enter OTP: ")
if time.time() > expiry_time:
print("⏰ OTP expired! Please request a new one.")
break
if user_otp == str(otp):
print("✅ OTP verified! Access granted.")
break
else:
attempts -= 1
print(f"❌ Incorrect OTP! Attempts left: {attempts}")
if attempts == 0:
print("🚫 No more attempts left.")
break