| 102 | } |
| 103 | |
| 104 | bool WifiCredentialStore::addCredential(const std::string& ssid, const std::string& password) { |
| 105 | // Check if this SSID already exists and update it |
| 106 | const auto cred = find_if(credentials.begin(), credentials.end(), |
| 107 | [&ssid](const WifiCredential& cred) { return cred.ssid == ssid; }); |
| 108 | if (cred != credentials.end()) { |
| 109 | cred->password = password; |
| 110 | LOG_DBG("WCS", "Updated credentials for: %s", ssid.c_str()); |
| 111 | return saveToFile(); |
| 112 | } |
| 113 | |
| 114 | // Check if we've reached the limit |
| 115 | if (credentials.size() >= MAX_NETWORKS) { |
| 116 | LOG_DBG("WCS", "Cannot add more networks, limit of %zu reached", MAX_NETWORKS); |
| 117 | return false; |
| 118 | } |
| 119 | |
| 120 | // Add new credential |
| 121 | credentials.push_back({ssid, password}); |
| 122 | LOG_DBG("WCS", "Added credentials for: %s", ssid.c_str()); |
| 123 | return saveToFile(); |
| 124 | } |
| 125 | |
| 126 | bool WifiCredentialStore::removeCredential(const std::string& ssid) { |
| 127 | const auto cred = find_if(credentials.begin(), credentials.end(), |