move credentials into struct
This commit is contained in:
parent
6a2b4df655
commit
bb1a67c49d
4 changed files with 15 additions and 9 deletions
|
@ -27,18 +27,18 @@ namespace firewall
|
|||
|
||||
ok_t API::setup_auth(const char *username, const char *password)
|
||||
{
|
||||
if (!username || *username == 0x00 || strlen(username) > sizeof(this->username))
|
||||
if (!username || *username == 0x00 || strlen(username) > CREDENTIALS_LENGTH)
|
||||
{
|
||||
log_e("Username too long or missing!");
|
||||
return ERROR;
|
||||
}
|
||||
strncpy(this->username, username, sizeof(this->username));
|
||||
if (!password || *password == 0x00 || strlen(password) > sizeof(this->password))
|
||||
strncpy(credentials.username, username, CREDENTIALS_LENGTH);
|
||||
if (!password || *password == 0x00 || strlen(password) > CREDENTIALS_LENGTH)
|
||||
{
|
||||
log_e("Password too long or missing!");
|
||||
return ERROR;
|
||||
}
|
||||
strncpy(this->password, password, sizeof(this->password));
|
||||
strncpy(credentials.password, password, CREDENTIALS_LENGTH);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -46,8 +46,8 @@ namespace firewall
|
|||
{
|
||||
std::string reqUsername = request->getBasicAuthUser();
|
||||
std::string reqPassword = request->getBasicAuthPassword();
|
||||
if ((strncmp(this->username, reqUsername.c_str(), sizeof(this->username)) != 0) ||
|
||||
(strncmp(this->password, reqPassword.c_str(), sizeof(this->password)) != 0))
|
||||
if ((strncmp(this->credentials.username, reqUsername.c_str(), CREDENTIALS_LENGTH) != 0) ||
|
||||
(strncmp(this->credentials.password, reqPassword.c_str(), CREDENTIALS_LENGTH) != 0))
|
||||
{
|
||||
this->json_message_response(response, "unauthorized", 403);
|
||||
return DENIED;
|
||||
|
|
Reference in a new issue