You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@kvrocks.apache.org by GitBox <gi...@apache.org> on 2022/09/17 15:55:41 UTC

[GitHub] [incubator-kvrocks] PragmaTwice commented on a diff in pull request #881: Implement the command `hello`

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: issues-unsubscribe@kvrocks.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org