0

I have a rather crude licence key for my software, which finds all of the mac addresses for a machine and encrypts them, then compares them with an encrypted value held in the registry. If the value in the registry matches any of the values that I have just found, then the software will load. I would expect that I would always get the same values for the MAC addresses, but for a few machines, that's not true. Can anyone explain why they MAC addresses aren't fixed, or how to over come this problem?

Thanks

        //// GET MAC ADDRESS
        String sMacAddress = String.Empty;
        ManagementScope theScope = new ManagementScope("\\\\" +Environment.MachineName + "\\root\\cimv2");
        DGCSLogger.log.Trace("Management scope");

        StringBuilder theQueryBuilder = new StringBuilder();

        theQueryBuilder.Append("SELECT MACAddress FROM Win32_NetworkAdapter");
        ObjectQuery theQuery = new ObjectQuery(theQueryBuilder.ToString());

        DGCSLogger.log.Trace("Creating searcher");

        ManagementObjectSearcher theSearcher = new ManagementObjectSearcher(theScope, theQuery);
        DGCSLogger.log.Trace("Creating collection");
        ManagementObjectCollection theCollectionOfResults = theSearcher.Get();

        DGCSLogger.log.Trace("Got management objects");

        //// GET VALUE FROM REGISTRY
        String sSavedScrambled = RegistryHelper.GetCurrentUserValue(@"Software\VB and VBA Program Settings\FMPos\settings", "LicenceKey");
        String sSavedLicenceKey = String.Empty;
        if (sSavedScrambled != null)
            sSavedLicenceKey = DGCS.Common.Password.UnScramblePassword(sSavedScrambled);

        String sMacNoLicenceKey = String.Empty;
        String sMacNo  = String.Empty;


         ///// COMPARE VALUES WITH REGISTRY VALUE
        foreach (ManagementObject theCurrentObject in theCollectionOfResults)
        {
            DGCSLogger.log.Trace("foreach object");

            if (theCurrentObject["MACAddress"] != null)
            {
                DGCSLogger.log.Trace("foreach object: " + theCurrentObject["MACAddress"].ToString().Substring(0, 5));

                String macAdd =  theCurrentObject["MACAddress"].ToString();

                sMacNo = DGCS.Common.Password.ScrambleMacNumber(theCurrentObject["MACAddress"].ToString());
                sMacNoLicenceKey = DGCS.Common.Password.CreateMacNoPassword(sMacNo);

                DGCSLogger.log.Trace(": " + theCurrentObject["MACAddress"].ToString().Substring(0, 5));

                if (sMacNoLicenceKey.Trim() == sSavedLicenceKey.Trim())
                    lkCheck.HasLicenceKey = true;
            }
        }
Edmund Covington
  • 521
  • 6
  • 17
  • 3
    _"Can anyone explain why they MAC addresses aren't fixed"_ - because they aren't. For the reason of this, ask the maintainer of the machine. It can be because of a variety of reasons. _"Or how to overcome this problem?"_ - see the 300 or so questions on _"how to implement a hardware-based software license key"_. – CodeCaster Jun 11 '13 at 09:26
  • I have changed the query to: theQueryBuilder.Append("SELECT MACAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=true"); This limits it to the one network adapter. It does mean that a licence key will need to be reentered if they change the netwrok adapter, but at least it means I am comparing against a constant value for the time being. – Edmund Covington Jun 11 '13 at 11:47

1 Answers1

0

Various possible reasons:

  1. They may have changed the network cards
  2. The WMI enumeration may return them in a different order (I don't see any sorting)
  3. They may actually change the MAC address (yes, this is possible)
  4. ...

That's why the MAC address is not actually a good reference for creating license keys.

Thorsten Dittmar
  • 55,956
  • 8
  • 91
  • 139