Skip to content

Commit bc9925a

Browse files
committed
fixed major bugs, added password for employees
1 parent 69760af commit bc9925a

File tree

6 files changed

+93
-17
lines changed

6 files changed

+93
-17
lines changed

check.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
def check():
2-
with open("firsttime.txt","r") as a:
3-
if a.read().strip()=="True":
4-
return True
5-
else:
6-
return False
2+
try:
3+
with open("firsttime.txt","r") as a:
4+
if a.read().strip()=="True":
5+
return True
6+
else:
7+
return False
8+
except FileNotFoundError:
9+
with open("firsttime.txt","w") as a:
10+
a.write("True")
11+
return True

editemployee.py

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ def ap3():
5252
print("4.last-name:",results1[3])
5353
print("5.gender:",results1[4])
5454
print("6.hire_date:",results1[5])
55+
print("7.password")
5556
birth_date=results1[1]
5657
hire_date=results1[5]
5758
f2()
@@ -268,9 +269,43 @@ def f2():
268269
traceback.print_exc()
269270
else:
270271
if age(birth_date)-age(hire_date)>=20:
271-
break
272+
try:
273+
cur.execute("update employees set hire_date='{}' where emp_no={}".format(hire_date,emp_no))
274+
conn.commit()
275+
except mysql.connector.Error as err:
276+
print(err.msg)
277+
print("-----------Value addition was unsuccessful!!!!-------------")
278+
break
279+
else:
280+
print("Updated hire date...")
281+
break
272282
else:
273283
print("Employee must atleast be 20 years of age when hired!!")
274-
284+
if a=='7':
285+
print("1.Show the password")
286+
print("2.Change the password")
287+
ans=input("Enter your choice (1,2):")
288+
if ans=='1':
289+
cur.execute("SELECT pass from empass where emp_no={}".format(emp_no))
290+
result=cur.fetchall()
291+
print(result[0][0], "is the password.")
292+
elif ans=='2':
293+
while True:
294+
password=input("Enter employee login password(max 8 characters, min 4): ")
295+
lp=len(password)
296+
if lp>8:
297+
print("Max 8 characters only.")
298+
elif lp<4:
299+
print("Minimum 4 characters to be entered.")
300+
else:
301+
try:
302+
cur.execute("UPDATE empass set pass=LPAD({},{},'0') where emp_no={}".format(password,lp,emp_no))
303+
conn.commit()
304+
except mysql.connector.Error as err:
305+
print(err.msg)
306+
print("-----------Password change was unsuccessful!!!!-------------")
307+
else:
308+
print("Password changed successfully!!!")
309+
break
275310
cur.close()
276311
conn.close()

fireemployee.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def ap2():
2222
else:
2323
print("Maximum length is 5!")
2424

25-
query="delete from employees where emp_no = {}".format(emp_no)
25+
query="delete from employees,empass where emp_no = {}".format(emp_no)
2626
cur.execute("select emp_no from employees")
2727
record=cur.fetchall()
2828
changed=False
@@ -34,7 +34,7 @@ def ap2():
3434
changed=True
3535
except mysql.connector.Error as err:
3636
print(err.msg)
37-
print("-----------Value addition was unsuccessful!!!!-------------\n")
37+
print("-----------Value deletion was unsuccessful!!!!-------------\n")
3838
else:
3939
print("Employee fired successfully...\n")
4040
if not changed:

hireemployee.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,5 +181,21 @@ def ap1():
181181
print("-----------Value addition was unsuccessful!!!!-------------")
182182
else:
183183
print("Values added successfully!!")
184+
while True:
185+
password=input("Enter employee login password(max 8 characters, min 4): ")
186+
if len(password)>8:
187+
print("Max 8 characters only.")
188+
elif len(password)<4:
189+
print("Minimum 4 characters to be entered.")
190+
else:
191+
try:
192+
cur.execute("INSERT INTO empass values({},LPAD({},{},'0')".format(emp_no,password,len(password)))
193+
query.commit()
194+
except mysql.connector.Error as err:
195+
print(err.msg)
196+
print("-----------Password addition was unsuccessful!!!!-------------")
197+
else:
198+
print("Password added successfully!!!")
199+
break
184200
cur.close()
185201
query.close()

main.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import setup
22
import check
33
import accounttype
4-
conn=setup.setup()
5-
if not check.check():
6-
accounttype.acctype()
4+
while True:
5+
if not check.check():
6+
accounttype.acctype()
7+
break
8+
else:
9+
setup.setup()

setup.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
from mysql.connector import errorcode
77
existing=0
8+
9+
conn=None
10+
cursor=None
11+
812
TABLES = {}
913
TABLES['employees'] = (
1014
"CREATE TABLE `employees` ("
@@ -27,10 +31,21 @@
2731
" `birth_date` date NOT NULL,"
2832
" `acc_creation_date` date NOT NULL,"
2933
" `mobile_no` int(10) NOT NULL,"
30-
" `email_id` varchar(25) NOT NULL"
34+
" `email_id` varchar(25) NOT NULL,"
35+
" `pass` varchar(8) NOT NULL"
36+
") "
37+
)
38+
39+
TABLES['empass'] = (
40+
"CREATE TABLE `empass` ("
41+
" `emp_no` int(5) NOT NULL,"
42+
" `pass` varchar(8) NOT NULL,"
43+
" PRIMARY KEY (`emp_no`),"
44+
" FOREIGN KEY(`emp_no`) REFERENCES employees(emp_no)"
3145
") "
3246
)
3347

48+
3449
TABLES['savings'] = (
3550
"CREATE TABLE `savings` ("
3651
" `acc_no` int(5) NOT NULL,"
@@ -108,6 +123,8 @@ def connectionquery():
108123
return query
109124

110125
def querycheck():
126+
global conn
127+
global cursor
111128
global existing
112129
conn=connectionquery()
113130
ans=False
@@ -130,8 +147,6 @@ def querycheck():
130147
print(err.msg())
131148
else:
132149
print("OK")
133-
with open("firsttime.txt","w") as f:
134-
f.write("False")
135150
ans=True
136151

137152
if not ans:
@@ -152,6 +167,8 @@ def mysqlsetup():
152167
querycheck()
153168

154169
def setup():
170+
global cursor
171+
global conn
155172
global existing
156173
while check.check():
157174
print("\n\n-----------------Welcome to the Project!!!-------------------")
@@ -165,7 +182,7 @@ def setup():
165182
break
166183
if ans2=="1":
167184
mysqlsetup()
168-
if existing==6:
185+
if existing==7:
169186
with open("firsttime.txt","w") as f:
170187
f.write("False")
171188
continue
@@ -175,4 +192,4 @@ def setup():
175192
print("\nWrong input, (1/2).........")
176193
else:
177194
if querycheck():
178-
connectionquery()
195+
return True

0 commit comments

Comments
 (0)