awacke1 commited on
Commit
5812d71
β€’
1 Parent(s): 64ce6fc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import hashlib
3
+ import streamlit as st
4
+ import textflowsms as tf
5
+
6
+ # Load the API key from an environment variable
7
+ api_key = os.getenv('API_KEY')
8
+ tf.useKey(api_key)
9
+
10
+ # Initialize session state variables if they don't exist
11
+ if 'phone_number' not in st.session_state:
12
+ st.session_state['phone_number'] = '9522583980' # Default phone number
13
+ if 'password' not in st.session_state:
14
+ st.session_state['password'] = ''
15
+
16
+ # Function to hash a password
17
+ def hash_password(password):
18
+ return hashlib.sha256(password.encode()).hexdigest()[:6]
19
+
20
+ # Mobile Phone field with emoji
21
+ st.sidebar.text_input("πŸ“± Mobile Phone", key='phone_number')
22
+
23
+ # Password field with emoji
24
+ password_input = st.sidebar.text_input("πŸ” Set Password", type='password')
25
+
26
+ # Button to save the password
27
+ if st.sidebar.button('Save Password'):
28
+ hashed_password = hash_password(password_input)
29
+ st.session_state['password'] = hashed_password
30
+ st.sidebar.success("Password set successfully!")
31
+
32
+ # Verify request button
33
+ if st.sidebar.button('Send Verify Request'):
34
+ # Generate verification URL with hashed password
35
+ verification_url = f"https://example.com/verify?code={st.session_state['password']}"
36
+ # Send the SMS
37
+ tf.sendSMS(recipient=st.session_state['phone_number'], text=f"Your verification link: {verification_url}")
38
+ st.sidebar.success("Verification link sent via SMS")
39
+
40
+ # Interface for login test
41
+ user_entered_code = st.text_input("πŸ”‘ Enter Verification Code")
42
+ if st.button('Login Test'):
43
+ # Verify the code
44
+ resultCode = tf.verifyCode(st.session_state['phone_number'], user_entered_code)
45
+ if resultCode.valid:
46
+ st.success("Phone number verified successfully!")
47
+ else:
48
+ st.error("Verification failed. Please try again.")
49
+
50
+ # Run the app
51
+ if __name__ == '__main__':
52
+ st.run()