While there's no explicit in-movie explanation given for this, it's not a stretch to say that Phasma and other stormies are fed identification information through a HUD inside their helmets. Books and other medium help confirm this.
I'd imagine something like a digital ID tag in the uniform that is scanned and read from inside the helmet of others.
According to Wookieepedia:
HUDs were also sometimes installed in helmets to assist warriors or bounty hunters. The visors of Mandalorian helmets and clone commando helmets contained HUDs that provided information to the user and were capable of searching databases or uploading maps. The clones became somewhat dependent on the information the HUD gave them, and often felt handicapped when their helmets were off.
This would allow for easy identification between troopers. Non-helmeted personnel and officers wouldn't gain that benefit but I don't recall any helmetless troopers showing up in combat situations. Except, perhaps, General Veers but he piloted an AT-AT and one could argue that trooper identification wasn't necessary inside the vehicle.
So we know that the Republic Commandos had advanced HUDs, at the very least. The Republic Commando video game confirmed trooper identification within the HUD:

We see troopers' nicknames above their heads and their trooper ID numbers docked in the lower left with their health status - exactly what we were expecting.
In addition, the Republic Commando books reference their HUD several times. Here are a couple excerpts from True Colors (Star Wars:Republic Commando Book 3):
Darman slipped on his helmet and retreated into his own world, comlinks closed except for the priority override that would let the squad break into the circuit and alert him. If he let his mind drift, the scrolling light display of his HUD blurred and became the nightscape of Coruscant, and he could immerse himself in the precious memory of those brief and illicit days in the city with Etain.
And:
Fi was back on the secure helmet comlink now. Darman’s red HUD audio icon indicated that only he could hear him.
Additionally, the Visual Dictionary has a cutout of the Stormtrooper helmet with this description:
In this model, enhanced optical equipment creates holographic images of the surrounding terrain, shielding the eye from excessive brightness and offering vision through many barriers such as smoke, darkness, and fire. Optical equipment in trooper helmets can range from simple eye lenses to these elaborate vision processors.
Not an exact confirmation but certainly a good indication. Perhaps low-ranking cannon fodder gets shafted on a decent HUD but there's precedent for at least higher ranking commandos to get them.
