so basically I'm trying to code a program that does something after you provide a correct key.
So, First I call Keycheck(Key) after getting Key from input then it irritates through a file with keys (each key is in a new line ("\n")).
def Keycheck(Key):
KeyFile = open("keys.key","r", encoding='utf-8')
for line in KeyFile:
line1 = line.strip()
fields = line1.split("\n")
linekey = fields[0]
if Key in linekey:
Keypass = "true"
elif Key != linekey:
continue
Well that works fine but the problem I'm having is to pass the Keypass variable to the main program, I tried reading about Kwargs but I couldn't understand it.
So my question is how do I pass the Keyword variable out of the "def Keycheck(Key)" and into the "main program", if that's not possible is there any other way to implement a key check from keys already stored in a file ?
EDIT: By main program I mean
def func():
def func2():
Keycheck(Key):
main program:
Key = input("")
Keycheck(Key)
if Keypass == "true":
func()
func2()
else:
break
Just a hint on how I want the program to work:
- it gets the key from input
- it calls Keycheck(Key) (or checks that the key is valid)
- it continues the program if the Key is in the file from Keycheck(key) If it does not contain the Key in the Keyfile then just print("wrong key try again") or something like that and retry everything