Basically, I have a SQL database which contains a json file with liscense keys which I link to my py software, the concept is simple in my json file there is the key with a "used" parameter if it is set to true the software tells us that we have an invalid key and asks us to re-enter a key if used is set to false then it leaves us access to the rest of the script but replaces false with true, but this does not mark it does not replace used by true and still leaves access to the rest of the script even if used is true, I don't know what to do anymore..
#🔒 pls i need help python
7 messages · Page 1 of 1 (latest)
@twilit geode
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
code :
config = {
'user': 'root',
'password': 'root',
'host': 'localhost',
'database': 'database',
'raise_on_warnings': True,
}
def check_key_usage(key_to_check):
try:
link = mysql.connector.connect(**config)
cursor = link.cursor()
query = "SELECT clee FROM ls_clee"
cursor.execute(query)
results = cursor.fetchall()
if results is not None:
for result in results:
json_data = json.loads(result[0])
keys = [entry["key"] for entry in json_data["license_keys"]]
if key_to_check in keys:
for entry in json_data["license_keys"]:
if entry["key"] == key_to_check and not entry["used"]:
print("La clé est valide et non utilisée.")
entry["used"] = True
update_query = "UPDATE ls_clee SET clee = %s WHERE clee = %s"
cursor.execute(update_query, (json.dumps(json_data), result[0]))
link.commit()
return True
print("La clé est déjà utilisée.")
return False
print("La clé n'existe pas.")
return False
else:
print("La table ne contient aucune clé.")
return False
cursor.close()
link.close()
except mysql.connector.Error as err:
print("Erreur MySQL :", err)
return False
while True:
license_key_to_check = input("Veuillez entrer une clé : ")
if check_key_usage(license_key_to_check):
print("Accès autorisé selon le script.")
break
json files syntax :
@twilit geode
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.