Whence keycodes?

How do people make license-restricted software? You know, 30-day trial edition, but when you enter your name, company, and keycode, the software says “Yeah, that’s fine.” Do people roll their own (and, if so, are there “best practices”), or is this a commercial market in which there are a few players (a la installers)?