| @@ 240-262 (lines=23) @@ | ||
| 237 | return $stmt->fetchColumn(); |
|
| 238 | } |
|
| 239 | ||
| 240 | public function setTotpSecret($userId, $totpSecret) |
|
| 241 | { |
|
| 242 | $userId = $this->getId($userId); |
|
| 243 | $stmt = $this->db->prepare( |
|
| 244 | <<< 'SQL' |
|
| 245 | INSERT INTO totp_secrets |
|
| 246 | (user_id, totp_secret) |
|
| 247 | VALUES |
|
| 248 | (:user_id, :totp_secret) |
|
| 249 | SQL |
|
| 250 | ); |
|
| 251 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_INT); |
|
| 252 | $stmt->bindValue(':totp_secret', $totpSecret, PDO::PARAM_STR); |
|
| 253 | ||
| 254 | try { |
|
| 255 | $stmt->execute(); |
|
| 256 | ||
| 257 | return true; |
|
| 258 | } catch (PDOException $e) { |
|
| 259 | // unable to add the TOTP secret, probably uniqueness contrains |
|
| 260 | return false; |
|
| 261 | } |
|
| 262 | } |
|
| 263 | ||
| 264 | public function deleteTotpSecret($userId) |
|
| 265 | { |
|
| @@ 614-638 (lines=25) @@ | ||
| 611 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
|
| 612 | } |
|
| 613 | ||
| 614 | public function recordTotpKey($userId, $totpKey, $timeUnix) |
|
| 615 | { |
|
| 616 | $userId = $this->getId($userId); |
|
| 617 | $stmt = $this->db->prepare( |
|
| 618 | <<< 'SQL' |
|
| 619 | INSERT INTO totp_log |
|
| 620 | (user_id, totp_key, time_unix) |
|
| 621 | VALUES |
|
| 622 | (:user_id, :totp_key, :time_unix) |
|
| 623 | SQL |
|
| 624 | ); |
|
| 625 | ||
| 626 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_INT); |
|
| 627 | $stmt->bindValue(':totp_key', $totpKey, PDO::PARAM_STR); |
|
| 628 | $stmt->bindValue(':time_unix', $timeUnix, PDO::PARAM_INT); |
|
| 629 | ||
| 630 | try { |
|
| 631 | $stmt->execute(); |
|
| 632 | } catch (PDOException $e) { |
|
| 633 | // unable to record the TOTP, probably uniqueness contrains |
|
| 634 | return false; |
|
| 635 | } |
|
| 636 | ||
| 637 | return true; |
|
| 638 | } |
|
| 639 | ||
| 640 | public function cleanConnectionLog($timeUnix) |
|
| 641 | { |
|