Skip to content

Commit 5e38558

Browse files
Update index.py
1 parent 330c51e commit 5e38558

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

index.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
import sqlite3
22

3-
def get_user_by_username(username):
4-
# This might look suspicious because of string formatting.
5-
query = "SELECT * FROM users WHERE username = '%s'" % sanitize_username(username)
3+
# Simulated config file or a settings module
4+
CONFIG = {
5+
"default_table": "users",
6+
"default_column": "username"
7+
}
8+
9+
def get_data_by_config_value(value):
10+
# This might look suspicious due to string concatenation with values from CONFIG.
11+
query = "SELECT * FROM " + CONFIG["default_table"] + " WHERE " + CONFIG["default_column"] + " = '" + value + "'"
612

713
connection = sqlite3.connect("database.db")
814
cursor = connection.cursor()
@@ -12,9 +18,5 @@ def get_user_by_username(username):
1218

1319
return result
1420

15-
def sanitize_username(username):
16-
# Only allow alphanumeric characters in the username.
17-
return ''.join(char for char in username if char.isalnum())
18-
1921
# Test
20-
print(get_user_by_username("admin"))
22+
print(get_data_by_config_value("admin"))

0 commit comments

Comments
 (0)