mapleFU commented on code in PR #881:
URL: https://github.com/apache/incubator-kvrocks/pull/881#discussion_r973596707
##########
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:
It's better to put `AuthenticateUser` and status to `Connection`, but here I
just want to make it lightweight to implement it, because `auth` isn't widely
used.
--
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]