blob: 47e1f6f6719d2b6ed7fc23a4c2c066ad3d02cf8a [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001<?php
2require_once("core.php");
3security::checkType(security::WORKER, security::METHOD_NOTFOUND);
4security::checkWorkerUIEnabled();
5secondFactor::checkAvailability();
6
7if (secondFactor::isEnabled()) {
8 security::notFound();
9}
10
11if (!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
21if (!secondFactor::checkCode($secret, $code)) {
22 security::go("security.php?msg=wrongcode");
23}
24
25if (secondFactor::enable($secret)) {
26 security::go("security.php?msg=enabledsecondfactor");
27} else {
28 security::go("security.php?msg=unexpected");
29}