I've looked everywhere for a compact combination lock that operates with buttons. The smallest build I found was using levers. I adapted it to buttons using a tflop. I wanted this for a gate entrance. The lock itself is small and simple.
You can make this as long as you want. You could do two rows, but it adds a lot of bulk and I was aiming to get it as small as possible.
In this instance, the lock will only trigger if buttons 1, 3 & 4 are pressed. You could extend the repeaters out further to allow more time to enter the code. If the wrong code is entered, there is a reset button. Once the correct combination is entered, a signal is sent through the redstone torch at the bottom left.This is the locklock itself.
To make the buttons react like levers, the signal is then sent to this tflop, which outputs a continuous signal.
A signal sent to a repeater abutting the hoppers (left), resets the item in the hopper, resetting the lock. The second block and repeater abutting the hoppers is a second reset switch I'll explain below.
For the gate, I've run the signal from the tflop on the far right, into an ABBA switch pushing out 2 pistons The back sticky piston pushes a regular piston into a set of iron bars. The ABBA then goes to a falling edge which runs a second ABBA to the two left pistons. The combination lock will cause the left pistons to push out a section of track, and push the iron bars out of the way, as soon as the right pistons retract.
Once the cart enters the track, it crosses a detector rail, which triggers the second reset mentioned above.
I don't know if anyone has a more compact lock. If so, I have been unable to find it