How do you send the username/password? I would guess when you have the ip you connect directly to it? Does it report something back than? Even if the username/password is not correct. During discovery you can connect and use what it reports back, if that is any useful information of course.
The ThingUID is less relevant because there is no direct relation between the device and the ThingUID. It’s free format. Technically any overlap would be coincidental. So you can set it to any string you want.
To avoid rediscovering you need to set some unique id and ip address could be cause or rediscovering the same device if the ip changes. But you can tackle that by setting the serial afterwards in the configuration if the device is authenticated. This will only cause rediscovering of unauthenticated devices that changed ip address.
B.t.w. There is a binding for the SMA energy meter. I don’t know if it uses the same communication protocol, but it might be worth looking at: https://github.com/openhab/openhab2-addons/tree/master/bundles/org.openhab.binding.smaenergymeter