public function registerLoginFailure(string $username, string $ip, int $numFailures = 0, HiddenString $password = null) : bool
{
$logAfter = $this->config['log-after'] ?? null;
if (!\is_null($logAfter)) {
$logAfter = (int) $logAfter;
}
$publicKey = (string) ($this->config['log-public-key'] ?? '');
$this->db->beginTransaction();
$inserts = ['action' => self::ACTION_LOGIN, 'occurred' => (new \DateTime())->format(\AIRSHIP_DATE_FORMAT), 'username' => $username, 'ipaddress' => $ip, 'subnet' => $this->getSubnet($ip)];
if (\is_int($logAfter) && !empty($publicKey)) {
if ($numFailures >= $logAfter) {
// Encrypt the password guess with the admin's public key
$inserts['sealed_password'] = Asymmetric::seal($password->getString(), $this->getLogPublicKey($publicKey));
}
}
$this->db->insert('airship_failed_logins', $inserts);
return $this->db->commit();
}