Setting Wifi and password in nodemcu

Dear all,

I am looking for sample code .where i could able to connect the nodemcu to my wifi network. Usually in all code the wifi name and password preentered and uploaded so it could able to connect to existing network and establish operation. How it can be made take input from Dashboard and connect to wifi network.

Means it should scan wifi network and on entering list of network Entering username and password it should get connected to wifi network.

#include "ESP8266WiFi.h"
 
void setup() {
 
  Serial.begin(115200);
 
  int numberOfNetworks = WiFi.scanNetworks();
 
  for(int i =0; i<numberOfNetworks; i++){
 
      Serial.print("Network name: ");
      Serial.println(WiFi.SSID(i));
      Serial.print("Signal strength: ");
      Serial.println(WiFi.RSSI(i));
      Serial.println("-----------------------");
 
  }
 
}
 
void loop() {}

Perhaps not exactly what you're looking for, but this library is a good solution for the general problem: https://github.com/tzapu/WiFiManager