Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Patched results for branch: master #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions sqli/dao/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,22 @@ async def get(conn: Connection, id_: int):
async def get_many(conn: Connection, limit: Optional[int] = None,
offset: Optional[int] = None):
q = 'SELECT id, name FROM students'
params = {}
params = []
if limit is not None:
q += ' LIMIT + %(limit)s '
params['limit'] = limit
q += ' LIMIT %s'
params.append(limit)
if offset is not None:
q += ' OFFSET + %(offset)s '
params['offset'] = offset
q += ' OFFSET %s'
params.append(offset)
async with conn.cursor() as cur:
await cur.execute(q, params)
results = await cur.fetchall()
return [Student.from_raw(r) for r in results]

@staticmethod
async def create(conn: Connection, name: str):
q = ("INSERT INTO students (name) "
"VALUES ('%(name)s')" % {'name': name})
async with conn.cursor() as cur:
await cur.execute(q)


await cur.execute(
"INSERT INTO students (name) VALUES (%s)",
(name,)
)
5 changes: 3 additions & 2 deletions sqli/dao/user.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from hashlib import md5
from hashlib import sha256
from typing import NamedTuple, Optional

from aiopg import Connection
Expand Down Expand Up @@ -38,4 +38,5 @@
return User.from_raw(await cur.fetchone())

def check_password(self, password: str):
return self.pwd_hash == md5(password.encode('utf-8')).hexdigest()
return self.pwd_hash == sha256(password.encode('utf-8')).hexdigest()

Check failure

Code scanning / CodeQL

Use of a broken or weak cryptographic hashing algorithm on sensitive data High

Sensitive data (password)
is used in a hashing algorithm (SHA256) that is insecure for password hashing, since it is not a computationally expensive hash function.

Loading