from __future__ import annotations import sqlite3 from datetime import datetime, timezone class CredentialsRepository: def __init__(self, conn: sqlite3.Connection) -> None: self._conn = conn @staticmethod def _now() -> str: return datetime.now(timezone.utc).isoformat(timespec="milliseconds").replace( "+00:00", "Z", ) def get_credential( self, access_point_id: int, handshake_id: int, password: str, ) -> sqlite3.Row | None: return self._conn.execute( """ SELECT id, access_point_id, handshake_id, password, source, created_at, verified FROM credentials WHERE access_point_id = ? AND handshake_id = ? AND password = ? LIMIT 1 """, ( access_point_id, handshake_id, password, ), ).fetchone() def create_hashcat_credential( self, access_point_id: int, handshake_id: int, password: str, ) -> int: cursor = self._conn.execute( """ INSERT INTO credentials ( access_point_id, handshake_id, password, source, created_at, verified ) VALUES (?, ?, ?, 'hashcat', ?, 0) """, ( access_point_id, handshake_id, password, self._now(), ), ) self._conn.execute( """ UPDATE access_points SET is_cracked = 1 WHERE id = ? """, (access_point_id,), ) return int(cursor.lastrowid) def mark_access_point_cracked( self, access_point_id: int, ) -> None: self._conn.execute( """ UPDATE access_points SET is_cracked = 1 WHERE id = ? """, (access_point_id,), )