This is an automated email from the ASF dual-hosted git repository.

jiahuili430 pushed a commit to branch fix-password-hasher-for-simple-scheme
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 3de50fe6cfc6a2339222d1b9d03f44553650b806
Author: Jiahui Li <[email protected]>
AuthorDate: Fri Dec 5 11:54:38 2025 -0600

    Avoid updating the user file with every request
    
    When using the `simple` password scheme, the user file is updated
    every time a new request is made because the number of iterations
    is undefined. Therefore, `needs_upgrade(UserProps)` always returns
    true.
    
    Add a case statement to avoid this situation.
---
 src/couch/src/couch_password_hasher.erl | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/couch/src/couch_password_hasher.erl 
b/src/couch/src/couch_password_hasher.erl
index 677d1c2f5..52c357a8e 100644
--- a/src/couch/src/couch_password_hasher.erl
+++ b/src/couch/src/couch_password_hasher.erl
@@ -42,6 +42,7 @@ maybe_upgrade_password_hash(Req, UserName, Password, 
UserProps, AuthModule, Auth
     UpgradeEnabled = config:get_boolean("chttpd_auth", "upgrade_hash_on_auth", 
true),
     IsDoc = is_doc(UserProps),
     NeedsUpgrade = needs_upgrade(UserProps),
+    io:format("~n +++++++ NeedsUpgrade:~p <- ~p:~p@~B~n", [NeedsUpgrade, 
?MODULE, ?FUNCTION_NAME, ?LINE]),
     InProgress = in_progress(AuthModule, UserName),
     if
         UpgradeEnabled andalso IsDoc andalso NeedsUpgrade andalso not 
InProgress ->
@@ -121,7 +122,12 @@ needs_upgrade(UserProps) ->
     TargetIterations = chttpd_util:get_chttpd_auth_config_integer(
         "iterations", 600000
     ),
+    io:format("~n +++++++ UserProps:~p <- ~p:~p@~B~n", [UserProps, ?MODULE, 
?FUNCTION_NAME, ?LINE]),
+    io:format("~n +++++++ {CurrentScheme, CurrentIterations, CurrentPRF}:~p <- 
~p:~p@~B~n", [{CurrentScheme, CurrentIterations, CurrentPRF}, ?MODULE, 
?FUNCTION_NAME, ?LINE]),
+    io:format("~n +++++++ {TargetScheme, TargetIterations, TargetPRF}:~p <- 
~p:~p@~B~n", [{TargetScheme, TargetIterations, TargetPRF}, ?MODULE, 
?FUNCTION_NAME, ?LINE]),
     case {TargetScheme, TargetIterations, TargetPRF} of
+        {CurrentScheme, _, _} when CurrentScheme == <<"simple">>, 
CurrentIterations =:= undefined ->
+            false;
         {CurrentScheme, CurrentIterations, _} when CurrentScheme == 
<<"simple">> ->
             false;
         {CurrentScheme, CurrentIterations, CurrentPRF} when CurrentScheme == 
<<"pbkdf2">> ->

Reply via email to