| @@ 193-210 (lines=18) @@ | ||
| 190 | return $stmt->fetchColumn(); |
|
| 191 | } |
|
| 192 | ||
| 193 | public function setTotpSecret($externalUserId, $totpSecret) |
|
| 194 | { |
|
| 195 | $userId = $this->getInternalUserId($externalUserId); |
|
| 196 | $stmt = $this->db->prepare( |
|
| 197 | 'INSERT INTO totp_secrets (user_id, totp_secret) VALUES(:user_id, :totp_secret)' |
|
| 198 | ); |
|
| 199 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 200 | $stmt->bindValue(':totp_secret', $totpSecret, PDO::PARAM_STR); |
|
| 201 | ||
| 202 | try { |
|
| 203 | $stmt->execute(); |
|
| 204 | } catch (PDOException $e) { |
|
| 205 | // unable to add the TOTP secret, probably uniqueness contrains |
|
| 206 | return false; |
|
| 207 | } |
|
| 208 | ||
| 209 | return true; |
|
| 210 | } |
|
| 211 | ||
| 212 | public function deleteTotpSecret($externalUserId) |
|
| 213 | { |
|
| @@ 465-493 (lines=29) @@ | ||
| 462 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
|
| 463 | } |
|
| 464 | ||
| 465 | public function recordTotpKey($externalUserId, $totpKey, $timeUnix) |
|
| 466 | { |
|
| 467 | $userId = $this->getInternalUserId($externalUserId); |
|
| 468 | $stmt = $this->db->prepare( |
|
| 469 | 'INSERT INTO totp_log ( |
|
| 470 | user_id, |
|
| 471 | totp_key, |
|
| 472 | time_unix |
|
| 473 | ) |
|
| 474 | VALUES( |
|
| 475 | :user_id, |
|
| 476 | :totp_key, |
|
| 477 | :time_unix |
|
| 478 | )' |
|
| 479 | ); |
|
| 480 | ||
| 481 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 482 | $stmt->bindValue(':totp_key', $totpKey, PDO::PARAM_STR); |
|
| 483 | $stmt->bindValue(':time_unix', $timeUnix, PDO::PARAM_INT); |
|
| 484 | ||
| 485 | try { |
|
| 486 | $stmt->execute(); |
|
| 487 | } catch (PDOException $e) { |
|
| 488 | // unable to record the TOTP, probably uniqueness contrains |
|
| 489 | return false; |
|
| 490 | } |
|
| 491 | ||
| 492 | return true; |
|
| 493 | } |
|
| 494 | ||
| 495 | public function cleanConnectionLog($timeUnix) |
|
| 496 | { |
|