Return-Path: X-Original-To: apmail-couchdb-dev-archive@www.apache.org Delivered-To: apmail-couchdb-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 18FDE17EEC for ; Fri, 31 Oct 2014 10:33:53 +0000 (UTC) Received: (qmail 82870 invoked by uid 500); 31 Oct 2014 10:33:52 -0000 Delivered-To: apmail-couchdb-dev-archive@couchdb.apache.org Received: (qmail 82806 invoked by uid 500); 31 Oct 2014 10:33:52 -0000 Mailing-List: contact dev-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list dev@couchdb.apache.org Received: (qmail 82795 invoked by uid 99); 31 Oct 2014 10:33:52 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 Oct 2014 10:33:52 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id F3F20A07B25; Fri, 31 Oct 2014 10:33:51 +0000 (UTC) From: kxepal To: dev@couchdb.apache.org Reply-To: dev@couchdb.apache.org References: In-Reply-To: Subject: [GitHub] couchdb-couch pull request: Implement two factor authentication Content-Type: text/plain Message-Id: <20141031103351.F3F20A07B25@tyr.zones.apache.org> Date: Fri, 31 Oct 2014 10:33:51 +0000 (UTC) Github user kxepal commented on a diff in the pull request: https://github.com/apache/couchdb-couch/pull/12#discussion_r19660168 --- Diff: src/couch_httpd_auth.erl --- @@ -430,3 +432,48 @@ max_age() -> config:get("couch_httpd_auth", "timeout", "600")), [{max_age, Timeout}] end. + +reject_if_totp(User) -> + case get_totp_config(User) of + undefined -> + ok; + _ -> + throw({unauthorized, <<"Name or password is incorrect.">>}) + end. + +verify_totp(User, Form) -> + case get_totp_config(User) of + undefined -> + ok; + {Props} -> + Key = couch_util:get_value(<<"key">>, Props), + Alg = couch_util:to_existing_atom( + couch_util:get_value(<<"algorithm">>, Props, <<"sha">>)), + Len = couch_util:get_value(<<"length">>, Props, 6), + Token = ?l2b(couch_util:get_value("token", Form, "")), + verify_token(Alg, Key, Len, Token) + end. + +get_totp_config(User) -> + couch_util:get_value(<<"totp">>, User). + +verify_token(Alg, Key, Len, Token) -> + Now = make_cookie_time(), + Tokens = [generate_token(Alg, Key, Len, Now - 30), --- End diff -- You decided to left the time unconfigurable for now? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---