I'm having some doubts about how can I "secure" the database's information to connect. There is someway that I can get the access to the database in a more secure way? A Rest Api? Or if someone can tell me a more secure that sending the access on the code
Thanks in advance
config = {
'user': 'user',
'password': 'password.',
'host': 'localhost',
'database': 'files_to_check',
'raise_on_warnings': True,
}
try:
# Try to connect to database
cnx = mysql.connector.connect(**config)
# Pointer of the sql
cursor = cnx.cursor()
# Query to get the files from the database
query = ("SELECT filename FROM filenames")
queryhash = ("SELECT hash FROM filenames")
# Execute the query
cursor.execute(query)
# select all the filenames from database
# array to fill with the files from the database
files_to_check = [str(row[0]) for row in cursor.fetchall()]
cursor.close()
cursor = cnx.cursor()
cursor.execute(queryhash)
# array to fill with the hash from the database
hash_to_check = [str(row[0]) for row in cursor.fetchall()]
# Error definition on connection
except mysql.connector.Error as err:
# Check username and password
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("[*] Username or password are invalid")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
# Check if database that are connection exists
print("[*] Database does not exist")
else:
print(err)
else:
cnx.close()
config.jsonand then in codeconfig = json.load(open("config.json"))'localhost'?