nickva commented on code in PR #5032:
URL: https://github.com/apache/couchdb/pull/5032#discussion_r1575034941


##########
src/couch/src/couch_auth_lockout.erl:
##########
@@ -0,0 +1,65 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License.  You may obtain a copy 
of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_auth_lockout).
+-include_lib("couch/include/couch_db.hrl").
+
+-define(LRU, couch_lockout_lru).
+
+-export([is_locked_out/3, lockout/3]).
+
+is_locked_out(#httpd{} = Req, UserName, UserSalt) ->
+    case config:get_boolean("couch_lockout", "enable", true) of
+        true ->
+            is_locked_out_int(Req, UserName, UserSalt);
+        false ->
+            false
+    end.
+
+is_locked_out_int(#httpd{} = Req, UserName, UserSalt) ->
+    LockoutThreshold = config:get_integer("couch_lockout", "threshold", 5),
+    case peer(Req) of
+        nopeer ->
+            false;
+        Peer ->
+            case ets_lru:lookup_d(?LRU, {Peer, UserName, UserSalt}) of
+                {ok, FailCount} when FailCount >= LockoutThreshold ->
+                    true;
+                {ok, _} ->
+                    false;
+                not_found ->
+                    false
+            end
+    end.
+
+lockout(#httpd{} = Req, UserName, UserSalt) ->
+    case peer(Req) of
+        nopeer ->
+            ok;
+        Peer ->
+            case config:get_boolean("couch_lockout", "enable", true) of

Review Comment:
   Since we have a helper function for `peer` would it make sense to have 
another for `enable`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to