-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgateman.py
111 lines (86 loc) · 3.09 KB
/
gateman.py
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import sqlite3
import streamlit as st
import pandas as pd
import hashlib
conn = sqlite3.connect('watchman.db')
c = conn.cursor()
gatePass = sqlite3.connect('gatepass.db')
gate = gatePass.cursor()
gate.execute('CREATE TABLE IF NOT EXISTS marketPassTable(username TEXT,otp TEXT,datetime TEXT,expectedDateTime TEXT)')
def check_otp(username,userOTP):
gate.execute('SELECT otp FROM marketPassTable WHERE username =?',(username,))
data = gate.fetchall()
if str(userOTP) == data[0][0]:
return True
return False
def make_hashes(password):
return hashlib.sha256(str.encode(password)).hexdigest()
def check_hashes(password,hashed_text):
if make_hashes(password) == hashed_text:
return hashed_text
return False
def login_user(username,password):
c.execute('SELECT * FROM watchManTable WHERE username =? AND password = ?',(username,password))
data = c.fetchall()
return data
def deleteData(username,userOTP):
gate.execute("SELECT username,otp from marketPassTable where username =? and otp=?",(username,userOTP))
data = gate.fetchall()
if data:
gate.execute('DELETE FROM marketPassTable WHERE username =? AND otp=?',(username,userOTP,))
gatePass.commit()
st.success("Deleted SuccessFully!")
else:
st.warning("Record Not Found!")
def main():
"""Simple Login App"""
st.title("WatchMan GatePass Dashboard")
menu = ["Home","Login"]
choice = st.sidebar.selectbox("Menu",menu)
if choice == "Home":
st.subheader("Home")
elif choice == "Login":
st.subheader("Login Section")
username = st.sidebar.text_input("User Name")
password = st.sidebar.text_input("Password",type='password')
if st.sidebar.checkbox("Login"):
# if password == '12345':
hashed_pswd = make_hashes(password)
result = login_user(username,check_hashes(password,hashed_pswd))
if result:
st.success("Logged in as {}".format(username))
task = st.selectbox("Tasks",["Check Gate Pass", "Remove Gate Pass"])
if task == "Check Gate Pass":
userName = st.text_input("Enter User Name")
userOTP = st.text_input("Enter OTP Here: ")
if st.button("Submit: "):
if check_otp(userName,userOTP):
st.success("You Can Go! OTP is Correct! Good Journeys {}".format(userName))
else:
st.warning("Invalid OTP!")
elif task == "Remove Gate Pass":
userName = st.text_input("Enter User Name")
userOTP = st.text_input("Enter OTP Here: ")
if st.button("Submit: "):
deleteData(userName,userOTP)
def hideFooter():
hide_streamlit_style = """
<style>
#MainMenu {visibility: hidden;}
footer {
visibility: hidden;
}
footer:after {
content:'Made With ❤️ By MrTechnoStart';
visibility: visible;
display: block;
position: relative;
#background-color: red;
padding: 5px;
top: 2px;
}
</style>
"""
st.markdown(hide_streamlit_style, unsafe_allow_html=True)
hideFooter()
main()