Copybara bot | be50d49 | 2023-11-30 00:16:42 +0100 | [diff] [blame^] | 1 | <?php |
| 2 | require_once("core.php"); |
| 3 | security::checkType(security::WORKER, security::METHOD_NOTFOUND); |
| 4 | security::checkWorkerUIEnabled(); |
| 5 | secondFactor::checkAvailability(); |
| 6 | |
| 7 | if (secondFactor::isEnabled()) { |
| 8 | security::notFound(); |
| 9 | } |
| 10 | |
| 11 | if (!security::checkParams("POST", [ |
| 12 | ["secret", security::PARAM_ISSET], |
| 13 | ["code", security::PARAM_ISINT] |
| 14 | ])) { |
| 15 | security::go("security.php?msg=empty"); |
| 16 | } |
| 17 | |
| 18 | $secret = (string)$_POST["secret"]; |
| 19 | $code = (string)$_POST["code"]; |
| 20 | |
| 21 | if (!secondFactor::checkCode($secret, $code)) { |
| 22 | security::go("security.php?msg=wrongcode"); |
| 23 | } |
| 24 | |
| 25 | if (secondFactor::enable($secret)) { |
| 26 | security::go("security.php?msg=enabledsecondfactor"); |
| 27 | } else { |
| 28 | security::go("security.php?msg=unexpected"); |
| 29 | } |