| @@ 176-193 (lines=18) @@ | ||
| 173 | return $stmt->fetchColumn(); |
|
| 174 | } |
|
| 175 | ||
| 176 | public function setTotpSecret($externalUserId, $totpSecret) |
|
| 177 | { |
|
| 178 | $userId = $this->getUserId($externalUserId); |
|
| 179 | $stmt = $this->db->prepare( |
|
| 180 | 'INSERT INTO totp_secrets (user_id, totp_secret) VALUES(:user_id, :totp_secret)' |
|
| 181 | ); |
|
| 182 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 183 | $stmt->bindValue(':totp_secret', $totpSecret, PDO::PARAM_STR); |
|
| 184 | ||
| 185 | try { |
|
| 186 | $stmt->execute(); |
|
| 187 | } catch (PDOException $e) { |
|
| 188 | // unable to add the TOTP secret, probably uniqueness contrains |
|
| 189 | return false; |
|
| 190 | } |
|
| 191 | ||
| 192 | return true; |
|
| 193 | } |
|
| 194 | ||
| 195 | public function deleteTotpSecret($externalUserId) |
|
| 196 | { |
|
| @@ 416-444 (lines=29) @@ | ||
| 413 | return $stmt->fetchAll(PDO::FETCH_ASSOC); |
|
| 414 | } |
|
| 415 | ||
| 416 | public function recordTotpKey($externalUserId, $totpKey, $timeUnix) |
|
| 417 | { |
|
| 418 | $userId = $this->getUserId($externalUserId); |
|
| 419 | $stmt = $this->db->prepare( |
|
| 420 | 'INSERT INTO totp_log ( |
|
| 421 | user_id, |
|
| 422 | totp_key, |
|
| 423 | time_unix |
|
| 424 | ) |
|
| 425 | VALUES( |
|
| 426 | :user_id, |
|
| 427 | :totp_key, |
|
| 428 | :time_unix |
|
| 429 | )' |
|
| 430 | ); |
|
| 431 | ||
| 432 | $stmt->bindValue(':user_id', $userId, PDO::PARAM_STR); |
|
| 433 | $stmt->bindValue(':totp_key', $totpKey, PDO::PARAM_STR); |
|
| 434 | $stmt->bindValue(':time_unix', $timeUnix, PDO::PARAM_INT); |
|
| 435 | ||
| 436 | try { |
|
| 437 | $stmt->execute(); |
|
| 438 | } catch (PDOException $e) { |
|
| 439 | // unable to record the TOTP, probably uniqueness contrains |
|
| 440 | return false; |
|
| 441 | } |
|
| 442 | ||
| 443 | return true; |
|
| 444 | } |
|
| 445 | ||
| 446 | public function cleanConnectionLog($timeUnix) |
|
| 447 | { |
|