An improved optical security system based on correlation between two phase-only computer generated masks is proposed. The two phase masks are placed together at the input plane of a joint transform correlator. A priori known output image is obtained in the system output only if one mask is the right key for the other mask. In addition to a simple verification, our security system is capable of identifying the type of an input mask according to the corresponding output image that it generates. The two phase masks are designed using an iterative optimization algorithm with constraints in the input and output domains. Computer simulations are presented with the resultant images formed by the two phase-only elements. © 2001 Society of Photo-Optical Instrumentation Engineers.