Minecraft wiki entry for Command_blocks_and_functions, associated text: Players can now create passwords with command blocks, using the if block argument on /execute. Place a command block. This will be the one you put input in. Place another command block, and type in the following command:
/execute if block <x, y, z coordinates of first command block> command_block{Command:"<input>"}
Example:
/execute if block ~2 ~ ~ command_block{Command:"That's Numberwang!"}
Place a comparator connected to the second command block, and place a button on or next to it to power the block. Now type "That's Numberwang!" (without quotes). If the second command block properly finds the first, the comparator will activate whatever it's wired to. If you want the first command block to reset so the password isn't used by someone else, also place a command block with /setblock that activates after /execute.