If I have two WiFi routers in different locations but with the same SSIDs and I connect a device to one of them, when I bring this device near the location of the other router, it will automatically connect to it as well.
I am wondering how this is not a security issue. In my understanding for a router to connect with a device this device has to send the password to the router and the router then checks if it is correct and connects with the device in case it is. Now what if I have a secured WiFi network A that I don't know the password to and I spin up my own network B with the same SSID near by, couldn't I just wait for one of the devices connected to A to send the password for A to me, because it would like to connect to me, too?
Obviously this is not possible, but I would like to know about the mechanism that prohibits this from happening.