File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change 1
1
import sqlite3
2
2
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 + "'"
6
12
7
13
connection = sqlite3 .connect ("database.db" )
8
14
cursor = connection .cursor ()
@@ -12,9 +18,5 @@ def get_user_by_username(username):
12
18
13
19
return result
14
20
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
-
19
21
# Test
20
- print (get_user_by_username ("admin" ))
22
+ print (get_data_by_config_value ("admin" ))
You can’t perform that action at this time.
0 commit comments