MatthewKing / DeviceId

A simple library providing functionality to generate a 'device ID' that can be used to uniquely identify a computer.
MIT License
722 stars 118 forks source link

Validating device id when you have multiple versions #85

Open andrewwong0893 opened 4 months ago

andrewwong0893 commented 4 months ago

Hello,

Correct me if I am wrong but I have the following example:

var id = new DeviceIdBuilder()
    .AddMachineName()
    .AddMacAddress(excludeWireless: true)
    .OnWindows(windows => windows.AddMachineGuid());

var idManager = new DeviceIdManager()
    .AddBuilder(1, builder => builder
        .AddMacAddress(excludeWireless: true)
        .OnWindows(windows => windows.AddMachineGuid()))
    .AddBuilder(2, builder => builder
        .AddMachineName()
        .AddMacAddress(excludeWireless: true)
        .OnWindows(windows => windows.AddMachineGuid()));

If I were to run the following

var isValid = idManager.Validate(id.ToString());

I get a failed result when I expected this to pass.

If I was to comment out the .AddMachineName() and then run it, version one of the ID Manager would then say it is valid.

When I dived into validate method of the ID Manager, it looks like I am expecting to send a string of the following format: ${version}${deviceId}

This seems counter-intuitive as the DeviceIdBuilder does not output a version.

Looking into your other methods in DeviceIdManager, you have an override for ToString which basically does the exact same thing as the builder but it includes the version number in.

Should I be using the manager instead?

MatthewKing commented 4 months ago

Hello. Yep, you should be using the manager. DeviceIdBuilder knows nothing about versions. You need to use DeviceIdManager to generate your versioned device ID, using the DeviceIdManager.GetDeviceId method (or the ToString method).