Yes it is prone to injection. If someone for example enters foo";--
as the login username, they could login to the account named foo
without any password checking:
user = 'foo";--'
passw = 'anything here'
sql = 'select * from users where username="' + user + '" and password="' + passw + '";'
print(sql)
Output (with SQL syntax highlighting):
select * from users where username="foo";--" and password="anything here";
There are also a million other ways that your original code is vulnerable to injection, the point is that you should never ever do simple string building for SQL statements.
You can should simply use parametrized queries to avoid this. On top of being 100% secure against injection, they make complicated queries much more simple to write and read:
import cgi
import sqlite3
form = cgi.FieldStorage()
user = form['username'].value
passw = form['password'].value
conn = sqlite3.connect('class.db')
c = conn.cursor()
c.execute('select * from users where username = ? and password = ?;', (user, passw))
results = c.fetchall()
conn.close()