Skip to content

Instantly share code, notes, and snippets.

@rnewson
Created April 6, 2014 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rnewson/10008876 to your computer and use it in GitHub Desktop.
Save rnewson/10008876 to your computer and use it in GitHub Desktop.
diff --git a/src/couchdb/couch_httpd_auth.erl b/src/couchdb/couch_httpd_auth.erl
index 08841fb..91acc1d 100644
--- a/src/couchdb/couch_httpd_auth.erl
+++ b/src/couchdb/couch_httpd_auth.erl
@@ -367,12 +367,21 @@ authenticate(Pass, UserProps) ->
{couch_passwords:simple(Pass, UserSalt),
couch_util:get_value(<<"password_sha">>, UserProps, nil)};
<<"pbkdf2">> ->
- Iterations = couch_util:get_value(<<"iterations">>, UserProps, 10000),
+ Iterations = iterations(UserProps),
{couch_passwords:pbkdf2(Pass, UserSalt, Iterations),
couch_util:get_value(<<"derived_key">>, UserProps, nil)}
end,
couch_passwords:verify(PasswordHash, ExpectedHash).
+iterations(UserProps) ->
+ Default = 10000,
+ case couch_util:get_value(<<"iterations">>, UserProps, Default) of
+ Iterations when is_integer(Iterations) ->
+ Iterations;
+ _ ->
+ Default
+ end.
+
auth_name(String) when is_list(String) ->
[_,_,_,_,_,Name|_] = re:split(String, "[\\W_]", [{return, list}]),
?l2b(Name).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment