CodeWitness

Audit a database query

Review how the input is added to this SQL statement.

def find_user(cursor, username):
    query = "SELECT id, name FROM users WHERE name = '" + username + "'"
    return cursor.execute(query).fetchone()

The value comes from outside the program. Prefer the database driver’s parameter binding instead of building SQL with string concatenation.

What is the safest way to use username in this query?