Does "lock code" mean you want to block execution?
If you use a modal dialog, you could keep the user in the dialog until there is a correct answer or cancellation.