
โ SQL Injection์ด๋?
์ฌ์ฉ์ ์ ๋ ฅ์ ์ด์ฉํด “์๋ํ์ง ์์ SQL ์ฟผ๋ฆฌ”๋ฅผ ์คํ์ํค๋ ๊ณต๊ฒฉ
์๋ฐฉ ๋ฐฉ๋ฒ: String Interpolation์ ์ฌ์ฉํ์ง ์๋๋ค.
import sqlite3
connection = sqlite3.connect("users.db")
cursor = connection.cursor()
def init_table():
cursor.execute(
"""
CREATE TABLE users (
user_id integer primary key autoincrement,
username text not null,
password text not null
);
"""
)
cursor.execute(
"""
insert into users (username, password)
values ('nico', 123), ('lynn', 321);
"""
)
def print_all_users():
result = cursor.execute("select * from users;")
data = result.fetchall()
print(data)
def i_change_password(username, new_password):
cursor.execute(
f"UPDATE users SET password = '{new_password}' WHERE username = '{username}'"
)
def s_change_password(username, new_password):
cursor.execute(
"UPDATE users SET password = ? WHERE username = ?", (new_password, username)
)
i_change_password("nico", "hached' --")
print_all_users()
connection.commit()
connection.close()

'๐งฉ SQL' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
| SQL - Drizzle(ORM) (0) | 2026.04.13 |
|---|---|
| SQL - SQL with Python (0) | 2026.04.13 |
| SQL - PostgreSQL, Extensions (0) | 2026.04.06 |
| SQL - PostgreSQL, JSON Column (0) | 2026.04.06 |
| SQL - PostgreSQL, DCL(Data Control Language) (0) | 2026.04.03 |