| @@ 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 | { |
|
| @@ 475-503 (lines=29) @@ | ||
| 472 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
|
| 473 | } |
|
| 474 | ||
| 475 | public function recordTotpKey($externalUserId, $totpKey, $timeUnix) |
|
| 476 | { |
|
| 477 | $userId = $this->getInternalUserId($externalUserId); |
|
| 478 | $stmt = $this->db->prepare( |
|
| 479 | 'INSERT INTO totp_log ( |
|
| 480 | user_id, |
|
| 481 | totp_key, |
|
| 482 | time_unix |
|
| 483 | ) |
|
| 484 | VALUES( |
|
| 485 | :user_id, |
|
| 486 | :totp_key, |
|
| 487 | :time_unix |
|
| 488 | )' |
|
| 489 | ); |
|
| 490 | ||
| 491 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 492 | $stmt->bindValue(':totp_key', $totpKey, PDO::PARAM_STR); |
|
| 493 | $stmt->bindValue(':time_unix', $timeUnix, PDO::PARAM_INT); |
|
| 494 | ||
| 495 | try { |
|
| 496 | $stmt->execute(); |
|
| 497 | } catch (PDOException $e) { |
|
| 498 | // unable to record the TOTP, probably uniqueness contrains |
|
| 499 | return false; |
|
| 500 | } |
|
| 501 | ||
| 502 | return true; |
|
| 503 | } |
|
| 504 | ||
| 505 | public function cleanConnectionLog($timeUnix) |
|
| 506 | { |
|