The codes are matched to voiceprints stored in the computers. Just like a username/password combination, they must match.
From Memory Alpha:
In 2372 Neelix was able to gain access to Tom Paris's computer with an
engineering authorization code (Engineering-Authorization-Omega-4-7)
without the proper voiceprint of Paris. (VOY: "Investigations")
Apparently, Starfleet is still just as unable to find a security technology that actually works as we are in this day. ;-) You'd think they'd be using multi-factor authentication at least.
In Starfleet, the style of code varies from decade to decade. In 2365,
the code was a long sequence of numbers, letters from the Human Greek
and English alphabet pronounced phonetically and colors. By the
following year, the code standardized to a form used from that point
on. Typically, this would involve the user's name, Greek letters, and
numbers. Codes are changed on a regular basis, to prevent sabotage and
security breaches.
So not only is it possible for a cook to figure out how to bypass the security, they are using an easy-to-guess pattern for coming up with passwords. Apparently the need to protect the self-destruct must not be that great, given the lax security protocols.
The Memory Alpha article does at least say they change their passwords frequently. Hopefully they know about the dangers of password re-use.