Note: This answer does NOT meet the requirements of the question, given that a door cannot be placed on a redstone comparator. However, I'm leaving it due to the amount of effort I put into it. The underlying concept may still be useful to future readers. I should really avoid answering in the evenings from now on. 😂
This can be accomplished with two commands:
- The
tag
command can be used to serve as the "key". - The
testfor
command can be used to determine if a nearby player has the expected "key".
📝 Required Items
- 1 Command Block
- 1 Redstone Comparator
- 1 Redstone Dust
- 1 Block (any kind that allows placement of redstone dust)
- 2 Buttons
🧰 Configuration
Since you have three spots under the door and one to the side, place 1 command block, 1 redstone comparator, 1 block that allows placement of redstone dust, and 1 sprinkle of redstone dust in the following configuration:
The command block should be given the following command and configuration:
# Command (replace number in the tag with the number of the door)
testfor @p[tag=door_number,r=3]
# Configuration
Repeat
Unconditional
Needs Redstone
50 Ticks
Giving a delay in ticks with a repeating configuration allows the door to automatically close once the player leaves the immediate area. You'll also need to use a button to trigger the command block from both sides of the door (allowing players to open the door):
🔑 Keys
You still need to give players the keys to their rooms, which you can do with the tag command:
tag player_name_here add door_number