you need to create a hash algorithm. and you need a database.
once a player registers - you send him a game key (example: 3D5B8-A3B8-etc.. ) and for that key you save yourself a HASH
that is generated once you pull through the whole key. (example, you get something like this: a7asdas7a6d876asdgdk12jb124).
that algorithm must give the same hash for that cd key EVERY TIME.
so when someone uses that CD KEY if hash is correct - enable download to that person (or whatever). OF course you can't control if it's the same person, but kinda does half of the anti-piracy job (example: i buy your game and give cd key to some friend. he plays your game like he's me but he's not me )