checkCredentials()

Description

Check whether username and password entered by the web client match a certain value.

Syntax

webserver.checkCredentials(authCredentials);

Parameters

authCredentials
Base64 encoded representation of valid <username>:<password>
The length of this parameter is currently limited to 44 characters in base64 encoded format, effectively limiting username and password combined to 32 characters, e.g. 16 characters username and 16 characters password. This should be practical.

Returns

Returns true if, otherwise returns false

Examples

#include "WebServer.h"

WebServer webserver; // defaults to no prefix, port 80

void privateCmd(WebServer &server, WebServer::ConnectionType type, char *, bool) {
  if (server.checkCredentials("dXNlcjp1c2Vy")) { // user:user in base64 is dXNlcjp1c2Vy
    server.httpSuccess();
    P(helloMsg) = "<h1>Hello User</h1>";
    server.printP(helloMsg);
  } else if (server.checkCredentials("YWRtaW46YWRtaW4=")) { // admin:admin in base64 is YWRtaW46YWRtaW4=
    server.httpSuccess();
    P(helloMsg) = "<h1>Hello Admin</h1>";
    server.printP(helloMsg);
  } else {
    server.httpUnauthorized();
  }
}

void setup() {
  // Ethernet stuff here, e.g. set MAC and IP address
  webserver.addCommand("private.html", &privateCmd);
  webserver.begin();
}

void loop() {
  webserver.processConnection();
}

« back to Webduino

  1. Using this example I am prompted to enter user/password the first time only. After that my credentials seem to be remembered and I automatically log on. How might I clear the credentials so that I am required to enter every time I access the web server?

    Thanks

  2. I experience the same thing.
    The credentials seem to be remembered.
    Is there a way to set it so that is required a log in every time?

Reply

Your email address will not be published.