Creating a Wi-fi Password generator using C++
Creating a Wi-fi Password generator using C++
Hello, coders. Welcome to the codewithrandom blog. In this article, we will learn how to create a simple Wifi Password Project using C++.
This is a simple C++ program which utilizes the Windows command prompt to obtain the user’s computer’s stored Wi-Fi passwords and save them to a text file. It is a simple App to retrieve passwords of your known WiFi networks that you have connected to before on your device. The retrieved passwords will be stored in a ‘.txt’ file. You can open the file to take a look at all the retrieved passwords.
Prison Management System using C++ (With Source Code)
You can directly use this code by copying it in your IDE to understand the working and then can create it by understanding the project.
#include <iostream> #include <sstream> #include <fstream> #include <string.h> #include <stdexcept> #include <stdio.h> #include <string> #include <vector> using namespace std; string exec(const char* cmd) { char buffer[128]; string result = ""; FILE* pipe = _popen(cmd, "r"); if (!pipe) throw runtime_error("_popen() failed!"); try { while (fgets(buffer, sizeof buffer, pipe) != NULL) { result += buffer; } } catch (...) { _pclose(pipe); throw; } _pclose(pipe); return result; } vector<string> getWifiList() { stringstream ss(exec("netsh wlan show profile").data()); string input; vector<string> wifi; while(getline(ss,input)) if (input.find("All User Profile") != string::npos) wifi.push_back(input.substr(27,input.length())); return wifi; } string getPassword(string ssid) { string command = "netsh wlan show profile \"" + ssid + "\" key=clear"; stringstream ss(exec(command.data()).data()); string input; while(getline(ss,input)){ if (input.find("Key Content") != string::npos) return input.substr(29,input.length()); } return "< NULL >"; } int main() { cout << "Getting list of known wifi networks..\n\n"; vector<string> wifi = getWifiList(); ofstream ofs("saved-wifi-passwords.txt"); for (string ssid: wifi) { cout << "Getting password for " << ssid << "..\n"; ofs << "SSID\t:\t" << ssid << "\n"; ofs << "Key\t:\t" << getPassword(ssid) << "\n\n"; } ofs.close(); cout << "\nOuput saved to `saved-wifi-passwords.txt`..\n"; return 0; }
Now let us understand the code:-
- We will start off by writing the header of the code with the required libraries – <iostream>, <sstream>, <fstream>, <string.h>, <stdexcept>, <stdio.h>, <string>, <vector>.
- Now we will define a function called exec that takes a command as a parameter and returns the output of that command. It uses error handling – try catch block, if statement and a while loop. This function is used to retrieve the Wi-Fi information.
- We will create a vector or string type called getWifiList(). It uses the function called exec to execute the “netsh wlan show profile” command and then retrieve a list of all the saved Wi-Fi networks for your device. Then this function extracts the SSID of each network and adds it to a vector of string type called wifi.
- Creating a function called getPassword of string type which takes SSID as a parameter constructs a ‘netsh’ command to retrieve the password for that network. It uses the ‘exec’ function to execute the command and retrieve the password from the output.
- The main() function firstly prints “Getting list of known wifi networks..”, on the console. It retrieves the list of saved Wi-Fi networks using ‘getWifiList’. It then iterates over each network, retrieves its password using ‘getPassword’, and saves the SSID and password to a text file called ‘saved-wifi-passwords.txt’.
- At last the program prints a message on the console stating that the output has been saved to the .txt file. We can check the password list in that file – “Ouput saved to `saved-wifi-passwords.txt`..”.
- This sums up our Simple Wi-fi Password Project using C++.
Simple College Management System using C++ (With Source Code)

Do you want to learn HTML to React? 🔥
If yes, then here is our Master HTML to React 📚 In this eBook, you’ll Get Complete Free Hand Written Notes on HTML, CSS, JavaScript, and React 💪. It includes 450 Projects with source code. and 250+ Most Asked Interview Questions
Get your eBook now! 👇
Final Output:-
Here is an example to show how this project works.
After running the C++ program on our IDE:
The passwords are saved in the saved-wifi-passwords.txt file.
Conclusion
We have reached the end of this article and have a lot more projects in C++ coming so stay tuned. We have started with awesome and fun projects for you all to understand C++. Learning C++ by creating fun projects makes learning easy and interesting.
Electricity Bill generator using C++ (With Source Code)
If you enjoyed the article and learned something new today, let us know in the comments.
Thank you.
Happy Reading! 🙂
Follow: CodeWithRandom