What potential security risks are present in the login system code provided in the forum thread?

The potential security risks present in the login system code provided in the forum thread include SQL injection vulnerabilities and lack of proper password hashing. To solve these issues, it is important to use prepared statements to prevent SQL injection attacks and to hash the passwords before storing them in the database.

// Fixing the potential security risks in the login system code

// Using prepared statements to prevent SQL injection
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username AND password = :password");
$stmt->execute(array('username' => $username, 'password' => $password));
$user = $stmt->fetch();

// Hashing the password before storing it in the database
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
$stmt = $pdo->prepare("INSERT INTO users (username, password) VALUES (:username, :password)");
$stmt->execute(array('username' => $username, 'password' => $hashed_password));