This project is read-only.

How to tell if incorrect password entered for?

Dec 14, 2007 at 6:29 PM

How can I tell if the incorrect password is entered for an available network? When I add a profile with an incorrect password, it returns Success (see code snippet below), and then it continually tries to connect to the network (unsuccessfully of course), but the status in the WlanAvailableNetworkFlags is set to connected... how can i detect an incorrect password? None of the WlanInterface events (WlanNotification, WlanConnectionNotification, WlanReasonNotification) that fire seem to tell any relevant info about this... ?

Wlan.WlanReasonCode wlanReasonCode = SelectedWlanInterface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, true);
if (wlanReasonCode != Wlan.WlanReasonCode.Success)
throw new WirelessException("Unsuccessful result from adding profile {0}: {1}", networkName, wlanReasonCode);

Any ideas? Thanks.

Mar 28, 2008 at 3:07 PM
I doesn't seem to me like the API provides any orderly way of knowing about an incorrect key, probably because the underlying 802.11 protocol provides no such notification either. The "password" is called a key: if you choose the right key, your packets are accepted by the AP - otherwise, they're dropped. Similarly, if you choose the right key, you could decrypt the packets. Otherwise, you have no way of even knowing who those encrypted packets belong to.

I'm not saying this from being familiar with the protocol, but just from extrapolation on the way it behaves (e.g. you enter a wrong key in the GUI tools and you're not notified about it -- you simply have 0 received packets).
Apr 24, 2008 at 6:52 PM
Hi, thanks for the post, but I figured out a workaround, by checking the IP address of the network, if it was empty, then it was connecting, then if it can't connect it. Here is a code snippet...
using System.Net;
using System.Net.NetworkInformation;

WlanClient.WlanInterface wlanInterface = <get from somewhere>;

// get all network interfaces on computer
NetworkInterface[] nics = NetworkInterface.GetAllNetworkInterfaces();
string ipAddresses = String.Empty;

// go through each network interface and find the one that matches this wireless interface
foreach (NetworkInterface adapter in nics)
if (String.Compare(adapter.Name, wlanInterface.InterfaceName, StringComparison.OrdinalIgnoreCase) == 0)
// go through all IPs addresses in this nic...
foreach (UnicastIPAddressInformation unicastIPAddress in adapter.GetIPProperties().UnicastAddresses)
string ipAddress = unicastIPAddress.Address.ToString();
// there are several non-identifiable ip addresses in adapter.GetIPProperties().DnsAddresses,
// so need to make a regex to get a real IP Address
if (System.Text.RegularExpressions.Regex.Match(ipAddress, @"(\d{1,3}\.){3}\d{1,3}").Success)
if (!String.IsNullOrEmpty(ipAddresses))
ipAddresses += ", ";
ipAddresses += ipAddress;
if (String.IsNullOrEmpty(ipAddresses))
ipAddresses = "Acquiring IP Address";