Skip to content

Instantly share code, notes, and snippets.

@iqfareez
Created July 5, 2022 16:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iqfareez/4861c6e5dc76c1190d8b1651def13d37 to your computer and use it in GitHub Desktop.
Save iqfareez/4861c6e5dc76c1190d8b1651def13d37 to your computer and use it in GitHub Desktop.
#include <WiFi.h>
#include <Wire.h>
#include <HTTPClient.h>
#define AP_SSID "IIUM-Student"
#define AP_PASSWORD "" // leaves empty if open wifi
const String username = "1111111";
const String password = "blahblah";
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
// Connecting to the WIFI AP
WiFi.begin(AP_SSID, AP_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("Connecting to WiFi..");
}
Serial.println("Connected to the WiFi network");
// Login to Captive Portal
HTTPClient login;
login.begin("http://captiveportalmahallahgombak.iium.edu.my/cgi-bin/login");
String body = "user=" + String(username) + "&password=" + String(password) + "&cmd=authenticate&Login=Log%2BIn";
int res = login.POST(body);
Serial.println(res);
if (res == 200) {
Serial.println("Authentication IIUM successful");
}
login.end();
}
void loop() {
// put your main code here, to run repeatedly:
HTTPClient http;
http.begin("https://iqfareez.com/api/hello");
int res = http.GET();
Serial.println(res); // status code
Serial.println(http.getString()); // API response
delay(2000);
}
@Johanjj
Copy link

Johanjj commented Nov 3, 2023

Hi thank you for sharing this code, it's really help me to figuring out how captive portal works with esp32. I still have a problem when try to login because captive portal in my campus is using hash MD5 for security. Here my payload tab in login response
image

Can you help me to solve this?
Thank you

@iqfareez
Copy link
Author

iqfareez commented Nov 3, 2023

@Johanjj You can try to use MD5 library for Arduino to Hash your password first before sending to the server. Example library I've found on the internet: https://github.com/tzikis/ArduinoMD5

@Johanjj
Copy link

Johanjj commented Nov 4, 2023

@Johanjj You can try to use MD5 library for Arduino to Hash your password first before sending to the server. Example library I've found on the internet: https://github.com/tzikis/ArduinoMD5

Apparently, it didn't work. I have checked web element code and looks like I should get/read hash md5 from JavaScript function.
image

Any idea how to read the value from this function before send with esp32 POST method?

@iqfareez
Copy link
Author

iqfareez commented Nov 6, 2023

@Johanjj Try inspect the webpage to see any JS file included. Then, perhaps you can the calcMD5 function. Then, try to port to cpp code for it to work with Arduino.

Example:

Screenshot 2023-11-06 at 10 06 15 AM

Edit:

Check this out:

@Johanjj
Copy link

Johanjj commented Nov 6, 2023

@iqfareez Thank you for giving me sources and information.

@Johanjj
Copy link

Johanjj commented Nov 11, 2023

Hi, can I have your email? I'd like to discuss via email if allowed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment