What they need to do is borrow from the automotive industry and develop some sort of "smart key" technology for the cockpit.
My stupid car (which I hate) does have an "intelligent key" which I have to admit, is pretty intelligent. I can't lock my keys in the car if I tried. It knows that the key is inside the car and I'm not. (Weight sensor in the seat.) It also remembers all my seat settings, mirror settings, etc. It will allow me to open the door if I'm outside and just push on a little rubber pad, but it won't allow a passenger to open their door, even if I'm standing right beside the car.
Now, applying this to the aircraft industry couldn't be so difficult could it. Each pilot has a transponder. It maybe be even woven into their belts. If there are not 2 pilots in the cockpit, the door can't be locked. The plane would then lock the autopilot on until such time as both pilots were back in their seats and the system registered the weight in the seat (over 100 pounds) and both transponders.
Hell, you could even go bio-tech with retina recognition. The system has to have the transponder, the weight in the seat and retina recognition or else the auto pilot remains on.
A back up could be that the system could be disabled by ATC should there be a system screw up.