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/pref/prefs.php | 85 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) (limited to 'classes/pref/prefs.php') diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index 705b709fa..c6b109877 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -154,12 +154,15 @@ class Pref_Prefs extends Handler_Protected { print ""; - $result = db_query($this->link, "SELECT email,full_name, + print "

" . __("Personal data") . "

"; + + $result = db_query($this->link, "SELECT email,full_name,otp_enabled, access_level FROM ttrss_users WHERE id = ".$_SESSION["uid"]); $email = htmlspecialchars(db_fetch_result($result, 0, "email")); $full_name = htmlspecialchars(db_fetch_result($result, 0, "full_name")); + $otp_enabled = sql_bool_to_bool(db_fetch_result($result, 0, "otp_enabled")); print ""; print "
".__('Full name')."" . __("Password") . ""; + $result = db_query($this->link, "SELECT id FROM ttrss_users WHERE id = ".$_SESSION["uid"]." AND pwd_hash = 'SHA1:5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'"); @@ -249,6 +254,55 @@ class Pref_Prefs extends Handler_Protected { print ""; + if ($_SESSION["auth_module"] == "internal") { + + print "

" . __("One time passwords / Authenticator") . "

"; + + if ($otp_enabled) { + + print "

".__("One time passwords are currently enabled. Change your current password and refresh this page to reconfigure.") . "

"; + + } else { + + print "

".__("You will need a compatible Authenticator to use this. Changing your password would automatically disable OTP.") . "

"; + + print "

".__("Scan the following code by the Authenticator application:")."

"; + + $csrf_token = $_SESSION["csrf_token"]; + + print ""; + + print "
"; + + print ""; + print ""; + + print ""; + + print " "; + print ""; + + print "

"; + + print "

"; + + } + + } } print ""; #pane @@ -571,5 +625,34 @@ class Pref_Prefs extends Handler_Protected { function toggleAdvanced() { $_SESSION["prefs_show_advanced"] = !$_SESSION["prefs_show_advanced"]; } + + function otpqrcode() { + require_once "lib/otphp/vendor/base32.php"; + require_once "lib/otphp/lib/otp.php"; + require_once "lib/otphp/lib/totp.php"; + require_once "lib/phpqrcode/phpqrcode.php"; + + $result = db_query($this->link, "SELECT login,salt + FROM ttrss_users + WHERE id = ".$_SESSION["uid"]); + + $base32 = new Base32(); + + $login = db_fetch_result($result, 0, "login"); + $secret = $base32->encode(sha1(db_fetch_result($result, 0, "salt"))); + + $topt = new \OTPHP\TOTP($secret); + + print QRcode::png($topt->provisioning_uri($login)); + } + + function changeotp() { + $enable_otp = $_REQUEST["enable_otp"]; + + if ($enable_otp == "on") { + db_query($this->link, "UPDATE ttrss_users SET otp_enabled = true WHERE + id = " . $_SESSION["uid"]); + } + } } ?> -- cgit v1.2.3