Project import generated by Copybara.
GitOrigin-RevId: 63746295f1a5ab5a619056791995793d65529e62
diff --git a/src/doenablesecondfactor.php b/src/doenablesecondfactor.php
new file mode 100644
index 0000000..47e1f6f
--- /dev/null
+++ b/src/doenablesecondfactor.php
@@ -0,0 +1,29 @@
+<?php
+require_once("core.php");
+security::checkType(security::WORKER, security::METHOD_NOTFOUND);
+security::checkWorkerUIEnabled();
+secondFactor::checkAvailability();
+
+if (secondFactor::isEnabled()) {
+ security::notFound();
+}
+
+if (!security::checkParams("POST", [
+ ["secret", security::PARAM_ISSET],
+ ["code", security::PARAM_ISINT]
+])) {
+ security::go("security.php?msg=empty");
+}
+
+$secret = (string)$_POST["secret"];
+$code = (string)$_POST["code"];
+
+if (!secondFactor::checkCode($secret, $code)) {
+ security::go("security.php?msg=wrongcode");
+}
+
+if (secondFactor::enable($secret)) {
+ security::go("security.php?msg=enabledsecondfactor");
+} else {
+ security::go("security.php?msg=unexpected");
+}