Skip to content

Commit f986219

Browse files
Create otp_bypass_mechanisms.py
1 parent 185f2e0 commit f986219

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import random
2+
import string
3+
import smtplib
4+
from email.mime.text import MIMEText
5+
from twilio.rest import Client
6+
7+
class OTPBypass:
8+
def __init__(self, email_server, email_port, email_user, email_password, twilio_sid, twilio_token, twilio_phone):
9+
self.email_server = email_server
10+
self.email_port = email_port
11+
self.email_user = email_user
12+
self.email_password = email_password
13+
self.twilio_sid = twilio_sid
14+
self.twilio_token = twilio_token
15+
self.twilio_phone = twilio_phone
16+
self.otp_store = {}
17+
18+
def generate_otp(self, length=6):
19+
otp = ''.join(random.choices(string.digits, k=length))
20+
return otp
21+
22+
def send_otp_email(self, recipient_email, otp):
23+
msg = MIMEText(f"Your OTP is: {otp}")
24+
msg['Subject'] = 'Your OTP Code'
25+
msg['From'] = self.email_user
26+
msg['To'] = recipient_email
27+
28+
with smtplib.SMTP(self.email_server, self.email_port) as server:
29+
server.starttls()
30+
server.login(self.email_user, self.email_password)
31+
server.sendmail(self.email_user, recipient_email, msg.as_string())
32+
33+
def send_otp_sms(self, recipient_phone, otp):
34+
client = Client(self.twilio_sid, self.twilio_token)
35+
message = client.messages.create(
36+
body=f"Your OTP is: {otp}",
37+
from_=self.twilio_phone,
38+
to=recipient_phone
39+
)
40+
41+
def validate_otp(self, user_id, otp):
42+
if user_id in self.otp_store and self.otp_store[user_id] == otp:
43+
return True
44+
return False
45+
46+
def bypass_otp(self, user_id):
47+
if user_id in self.otp_store:
48+
del self.otp_store[user_id]
49+
return True
50+
return False
51+
52+
def request_otp(self, user_id, contact_info, method='email'):
53+
otp = self.generate_otp()
54+
self.otp_store[user_id] = otp
55+
56+
if method == 'email':
57+
self.send_otp_email(contact_info, otp)
58+
elif method == 'sms':
59+
self.send_otp_sms(contact_info, otp)
60+
61+
def integrate_with_framework(self, user_id, contact_info, method='email'):
62+
self.request_otp(user_id, contact_info, method)
63+
# Add integration logic with existing framework here
64+
65+
# Example usage
66+
if __name__ == "__main__":
67+
otp_bypass = OTPBypass(
68+
email_server='smtp.example.com',
69+
email_port=587,
70+
email_user='[email protected]',
71+
email_password='password',
72+
twilio_sid='your_twilio_sid',
73+
twilio_token='your_twilio_token',
74+
twilio_phone='+1234567890'
75+
)
76+
77+
user_id = 'user123'
78+
contact_info = '[email protected]'
79+
otp_bypass.integrate_with_framework(user_id, contact_info, method='email')

0 commit comments

Comments
 (0)