LennartHennigs / ESPTelnet

ESP library that allows you to setup a telnet server for debugging.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Telnet username / password login

jamesarm97 opened this issue · comments

Has anyone implemented a username / password login using this library? Would it just be done by parsing the input and not allowing any commands to be issued?

I've just made it for myself, in case you still need it. It could get more complex but since it is exposed to my Wifi only this is fine for most of us

const char* password = "yourpass" //I use the same for OTA, WifiAP...
boolean passOK = false;
int passretry = 10;
String bannedIP ;

telnet.onInputReceived([](String str) {  // checks for a certain command   !!!!!!!!!!!
    if (passOK == false){
        if (str == password) { passOK = true; info();} else {
          passretry--; 
          if (passretry==0){
               bannedIP = telnet.getIP(); telnet.println("Fail, IP address banned !"); telnet.disconnectClient(); 
               passretry=10;
          } else {telnet.println("Incorrect ! ,"+ String(passretry) + " more attempts");}
        }
    } else {
        if (str == "info") { info(); } 
        else if (str == "update_firmware") { telnet.println("Updating system, hold on"); OTA_Updates(); }
        ......
          else if (str == "espreset") { telnet.println("> resetting ESP..."); delay(500); ESP.restart();}
    };

void onTelnetConnect(String ip) {
  if (telnet.getIP() == bannedIP) {telnet.disconnectClient();}
  telnet.println("\nWelcome " + telnet.getIP()); telnet.println("Please provide password :");
  passOK = false;
}

oh and reset retry on success connection would be good

if (str == password) { passOK = true; passretry=10; info();} else {

Hey @milansim,
thank you for sharing this!
Cheers
l.

this is not really done... every telnet.print() should be replaced with if (passOK == true){ telnet.print();} which would be a large task
Much better would be to implement it in your library !

I understand, but implementing logic for what you do want to do with the telnet connection is not in scope for me.