From fb70f26ed91dbd191351026d917afcef9d8d2eb1 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 3 Sep 2012 18:33:46 +0400 Subject: implement one time passwords using TOTP --- classes/auth/internal.php | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'classes/auth') diff --git a/classes/auth/internal.php b/classes/auth/internal.php index 8890d4455..a4e8b471c 100644 --- a/classes/auth/internal.php +++ b/classes/auth/internal.php @@ -6,6 +6,48 @@ class Auth_Internal extends Auth_Base { $pwd_hash1 = encrypt_password($password); $pwd_hash2 = encrypt_password($password, $login); $login = db_escape_string($login); + $otp = db_escape_string($_REQUEST["otp"]); + + if (get_schema_version($this->link) > 96) { + $result = db_query($this->link, "SELECT otp_enabled,salt FROM ttrss_users WHERE + login = '$login'"); + + require_once "lib/otphp/vendor/base32.php"; + require_once "lib/otphp/lib/otp.php"; + require_once "lib/otphp/lib/totp.php"; + + $base32 = new Base32(); + + $otp_enabled = sql_bool_to_bool(db_fetch_result($result, 0, "otp_enabled")); + $secret = $base32->encode(sha1(db_fetch_result($result, 0, "salt"))); + + $topt = new \OTPHP\TOTP($secret); + $otp_check = $topt->now(); + + if ($otp_enabled) { + if ($otp) { + if ($otp != $otp_check) { + return false; + } + } else { + ?> + Tiny Tiny RSS + +
+ + + + + + + +
+ + link) > 87) { @@ -104,7 +146,7 @@ class Auth_Internal extends Auth_Base { $new_password_hash = encrypt_password($new_password, $new_salt, true); db_query($this->link, "UPDATE ttrss_users SET - pwd_hash = '$new_password_hash', salt = '$new_salt' + pwd_hash = '$new_password_hash', salt = '$new_salt', otp_enabled = false WHERE id = '$owner_uid'"); $_SESSION["pwd_hash"] = $new_password_hash; -- cgit v1.2.3