| @@ 190-207 (lines=18) @@ | ||
| 187 | return $stmt->fetchColumn(); |
|
| 188 | } |
|
| 189 | ||
| 190 | public function setTotpSecret($externalUserId, $totpSecret) |
|
| 191 | { |
|
| 192 | $userId = $this->getUserId($externalUserId); |
|
| 193 | $stmt = $this->db->prepare( |
|
| 194 | 'INSERT INTO totp_secrets (user_id, totp_secret) VALUES(:user_id, :totp_secret)' |
|
| 195 | ); |
|
| 196 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 197 | $stmt->bindValue(':totp_secret', $totpSecret, PDO::PARAM_STR); |
|
| 198 | ||
| 199 | try { |
|
| 200 | $stmt->execute(); |
|
| 201 | } catch (PDOException $e) { |
|
| 202 | // unable to add the TOTP secret, probably uniqueness contrains |
|
| 203 | return false; |
|
| 204 | } |
|
| 205 | ||
| 206 | return true; |
|
| 207 | } |
|
| 208 | ||
| 209 | public function deleteTotpSecret($externalUserId) |
|
| 210 | { |
|
| @@ 430-458 (lines=29) @@ | ||
| 427 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
|
| 428 | } |
|
| 429 | ||
| 430 | public function recordTotpKey($externalUserId, $totpKey, $timeUnix) |
|
| 431 | { |
|
| 432 | $userId = $this->getUserId($externalUserId); |
|
| 433 | $stmt = $this->db->prepare( |
|
| 434 | 'INSERT INTO totp_log ( |
|
| 435 | user_id, |
|
| 436 | totp_key, |
|
| 437 | time_unix |
|
| 438 | ) |
|
| 439 | VALUES( |
|
| 440 | :user_id, |
|
| 441 | :totp_key, |
|
| 442 | :time_unix |
|
| 443 | )' |
|
| 444 | ); |
|
| 445 | ||
| 446 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 447 | $stmt->bindValue(':totp_key', $totpKey, PDO::PARAM_STR); |
|
| 448 | $stmt->bindValue(':time_unix', $timeUnix, PDO::PARAM_INT); |
|
| 449 | ||
| 450 | try { |
|
| 451 | $stmt->execute(); |
|
| 452 | } catch (PDOException $e) { |
|
| 453 | // unable to record the TOTP, probably uniqueness contrains |
|
| 454 | return false; |
|
| 455 | } |
|
| 456 | ||
| 457 | return true; |
|
| 458 | } |
|
| 459 | ||
| 460 | public function cleanConnectionLog($timeUnix) |
|
| 461 | { |
|