LennartHennigs / ESPTelnet

ESP library that allows you to setup a telnet server for debugging.
MIT License
215 stars 35 forks source link

How can I ask password (Hidden Input) to login? #24

Closed Katheesh closed 2 years ago

Katheesh commented 2 years ago

Please help me to find the correct function to ask for hidden input. please reply as soon as possible. Thanks.

Katheesh commented 2 years ago

image

LennartHennigs commented 2 years ago

Please post the code you used.

Katheesh commented 2 years ago

Thanks for the quick response. This is my code.

void setupTelnet() {  
  telnet.onConnect(onTelnetConnect);
  telnet.onConnectionAttempt(onTelnetConnectionAttempt);
  telnet.onReconnect(onTelnetReconnect);
  telnet.onDisconnect(onTelnetDisconnect);

  telnet.onInputReceived([](String str) {
    if(!IS_LOGGED_IN){
      if(TELNET_PSWD == str){
        IS_LOGGED_IN = true;
        telnet.print("DasKlug:> ");
        return;
      }
      telnet.print("Invalid Password. Try again...");
      telnet.print("Enter password to access telnet : ");
      return;
    }
    if(str == "" || str == " "){
      telnet.print("DasKlug:> ");
      return;
    }
    toCommand(1, str);
  });

  if (!telnet.begin(TELNET_PORT)) {
    Serial.println("Unable to start telnet...");
  }
}
void onTelnetConnect(String ip) {
  Serial.print("SMARTOMATION TELNET");
  Serial.print(ip);
  Serial.println(" connected");
  if(IS_LOGGED_IN){
    telnet.println("(Use Ctrl + ]  to quit)");
    telnet.println("\nWelcome " + telnet.getIP());
    telnet.println();
    telnet.print("DasKlug:> ");
    return;
  }
  if(!IS_LOGGED_IN){
    telnet.println("(Use Ctrl + ]  to quit)");
    telnet.print("Enter password to access telnet : ");
    return;
  }
}
LennartHennigs commented 2 years ago

Hey, I briefly looked into this and you want to look into ANSI escape sequences.

I have that on my list for telnet but didn't have the time yet.

Katheesh commented 2 years ago

Thanks, man...