diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index d2dc9ce3..ba332f91 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -118,19 +118,25 @@ class Adminer { */ function loginForm() { global $drivers; - ?> - -
-
-
" autocapitalize="off"> -
-
" autocapitalize="off"> -
-\n"; + echo $this->loginFormField('driver', '' . lang('System') . '' . html_select("auth[driver]", $drivers, DRIVER) . "\n"); + echo $this->loginFormField('server', '' . lang('Server') . '' . "\n"); + echo $this->loginFormField('username', '' . lang('Username') . '' . script("focus(qs('#username'));")); + echo $this->loginFormField('password', '' . lang('Password') . '' . "\n"); + echo $this->loginFormField('db', '' . lang('Database') . '' . "\n"); + echo "\n"; echo "

\n"; echo checkbox("auth[permanent]", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n"; } + + /** Get login form field + * @param string + * @param string HTML + * @return string + */ + function loginFormField($name, $default) { + return $default; + } /** Authorize the user * @param string diff --git a/editor/include/adminer.inc.php b/editor/include/adminer.inc.php index c6820f07..9e374130 100644 --- a/editor/include/adminer.inc.php +++ b/editor/include/adminer.inc.php @@ -71,17 +71,18 @@ class Adminer { } function loginForm() { - ?> - -
" autocapitalize="off"> -
-
-\n"; + echo $this->loginFormField('username', '' . lang('Username') . '' . script("focus(qs('#username'));")); + echo $this->loginFormField('password', '' . lang('Password') . '' . "\n"); + echo "\n"; echo "

\n"; echo checkbox("auth[permanent]", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n"; } + function loginFormField($name, $default) { + return $default; + } + function login($login, $password) { return true; } diff --git a/plugins/login-otp.php b/plugins/login-otp.php new file mode 100644 index 00000000..0b8dfe74 --- /dev/null +++ b/plugins/login-otp.php @@ -0,0 +1,52 @@ +secret = $secret; + if ($_POST["auth"]) { + $_SESSION["otp"] = (string) $_POST["auth"]["otp"]; + } + } + + function loginFormField($name, $default) { + if ($name == 'password') { + return $default . "OTP\n"; + } + } + + function login($login, $password) { + if (isset($_SESSION["otp"])) { + $timeSlot = floor(time() / 30); + foreach (array(0, -1, 1) as $skew) { + if ($_SESSION["otp"] == $this->getOtp($timeSlot + $skew)) { + restart_session(); + unset($_SESSION["otp"]); + stop_session(); + return; + } + } + return 'Invalid OTP.'; + } + } + + function getOtp($timeSlot) { + $data = str_pad(pack('N', $timeSlot), 8, "\0", STR_PAD_LEFT); + $hash = hash_hmac('sha1', $data, $this->secret, true); + $offset = ord(substr($hash, -1)) & 0xF; + $unpacked = unpack('N', substr($hash, $offset, 4)); + return ($unpacked[1] & 0x7FFFFFFF) % 1e6; + } +} diff --git a/plugins/plugin.php b/plugins/plugin.php index e7b1df14..5a5af671 100644 --- a/plugins/plugin.php +++ b/plugins/plugin.php @@ -160,6 +160,11 @@ class AdminerPlugin extends Adminer { return $this->_applyPlugin(__FUNCTION__, $args); } + function loginFormField($name, $default) { + $args = func_get_args(); + return $this->_applyPlugin(__FUNCTION__, $args); + } + function login($login, $password) { $args = func_get_args(); return $this->_applyPlugin(__FUNCTION__, $args);