PragmaTwice commented on code in PR #881:
URL: https://github.com/apache/incubator-kvrocks/pull/881#discussion_r973600563


##########
src/redis_cmd.cc:
##########
@@ -73,29 +74,47 @@ const char *errUnbalacedStreamList =
 const char *errTimeoutIsNegative = "timeout is negative";
 const char *errLimitOptionNotAllowed = "syntax error, LIMIT cannot be used 
without the special ~ option";
 
+enum class AuthResult {
+  OK,
+  INVALID_PASSWORD,
+  NO_REQUIRE_PASS,
+};
+
+AuthResult AuthenticateUser(Connection *conn, Config* config, const 
std::string& user_password) {
+  auto iter = config->tokens.find(user_password);
+  if (iter != config->tokens.end()) {
+    conn->SetNamespace(iter->second);
+    conn->BecomeUser();
+    return AuthResult::OK;
+  }
+  const auto& requirepass = config->requirepass;
+  if (!requirepass.empty() && user_password != requirepass) {
+    return AuthResult::INVALID_PASSWORD;
+  }
+  conn->SetNamespace(kDefaultNamespace);
+  conn->BecomeAdmin();
+  if (requirepass.empty()) {
+    return AuthResult::NO_REQUIRE_PASS;
+  }
+  return AuthResult::OK;
+}
+

Review Comment:
   I think it is OK to me. Actually I think it can be `Status 
AuthenticateUser(Connection *conn, Config* config, const std::string& 
user_password)`, but current form also looks good to me.



-- 
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