-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidatorControlRecursiveFunc.py
More file actions
162 lines (124 loc) · 4.66 KB
/
Copy pathvalidatorControlRecursiveFunc.py
File metadata and controls
162 lines (124 loc) · 4.66 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#Date: 1402.5.5
#Program: Check User Input
#Teacher: Soroush Joudaki
#Academy: Montazemi
#Programer: Amir Bagherzade
"""
1. gereftane name karbar
2. gereftane charactere controli va barresi
3. baressi inke tedadesh 8tast ya na
4. baressi inke adad tosh hast ya na
5. baressi inke horofe kochick tosh hast ya na
6. baressi inke horofe bozorg tosh hast ya na
7. baressi key vorodi karbar ba liste validkeys be onvane Data Base
8. soal az karbar baraye tamayol be ezafe kardane valid key jadid
9. soal az karbar baraye edame barname ya tamam shodanesh
"""
#--------------------------------------Libraries----------------------------------#
import os
#--------------------------------------DataBase----------------------------------#
validKeys=["S45E29tb","5kdI4i3V","77vV33Ee"] #Data Base List
charCheck="#" #Charactere Controli Khaste shode da inja "#" mibashad
#--------------------------------------Functions----------------------------------#
def UserName():
os.system('cls')
global userName
userName = input("Enter your name:") # gereftane name karbar
if userName == "":
userName = "Guest"
os.system('cls')
def ContorlChar():
charUser = input("Enter your control character:") #gereftane charactere controli va barresi
if charCheck == charUser:
pass
os.system('cls')
else:
os.system('cls')
print("The control character entered is incorrect!")
ContorlChar()
#/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\#
def GetInput(): #barresi vorodie karbar
keyUser = input("Enter your login key:")
keyUser = CountChar(keyUser)
keyUser = HaveNum(keyUser,0)
keyUser = HaveLower(keyUser,0)
keyUser = HaveUpper(keyUser,0)
os.system('cls')
return keyUser
def CountChar(stCount): #baressi inke tedadesh 8tast ya na
if len(stCount) == 8:
return stCount
else:
os.system('cls')
print("The input length is not correct! It should be 8 characters")
return GetInput()
def HaveNum(stNum,n): #baressi inke adad tosh hast ya na
if n == (len(stNum)-1) and stNum[n].isnumeric() == False:
os.system('cls')
print("Your entry does not have a number!")
stNum = GetInput()
return stNum
elif stNum[n].isnumeric():
return stNum
else:
stNum = HaveNum(stNum,n+1)
return stNum
def HaveLower(stLow,n): #baressi inke horofe kochick tosh hast ya na
if n == (len(stLow)-1) and stLow[n].islower() == False:
os.system('cls')
print("Your entry does not contain a lowercase character!")
stLow = GetInput()
return stLow
elif stLow[n].islower():
return stLow
else:
stLow = HaveLower(stLow,n+1)
return stLow
def HaveUpper(stUp,n): #baressi inke horofe bozorg tosh hast ya na
if n == (len(stUp)-1) and stUp[n].isupper() == False:
os.system('cls')
print("Your entry does not contain an uppercase character!")
stUp = GetInput()
return stUp
elif stUp[n].isupper():
return stUp
else:
stUp = HaveUpper(stUp,n+1)
return stUp
#/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\#
def CheckKeyUserWithDB(st): #barresi key vorodie karbar ba DataBase
if st in validKeys:
os.system('cls')
return st
else:
os.system('cls')
print("Your input key does not match the database keys!")
st = GetInput()
return st
#/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\#
def MainProgram(): #daryafte va barresi vorodi karbar va ehyanan vorode key jadid be data base
UserName()
ContorlChar()
CheckInput = GetInput()
CheckInput = CheckKeyUserWithDB(CheckInput)################################# ERROR LOGIC !!!!!!!!!!!!!!!!!!!!!!
print(f"Welcome Dear {userName}")
print("--------------------------\n")
ch = input("Do you want to enter a new key? (y/n)").lower()
if ch == 'y':
NewKeyUser = GetInput()
validKeys.append(NewKeyUser)
os.system('cls')
print("Dear {},\nYour new key has been successfully added to the database.\n".format(userName))
print(validKeys)
def MyProgram(): #baraye barresi inke karbar mikhad barname edame peida kone ya na
MainProgram()
choose = input("Do you want to log out? (y/n)").lower()
if choose == 'n':
MyProgram()
else:
os.system('cls')
print("Logout...")
print("Good Luck.")
#------------------------------------End_Functions--------------------------------#
#------------------------------------MAIN_PROGRAM--------------------------------#
MyProgram()