You didn't do anything wrong, use this instead:

on 1:INPUT:#channelnamehere:{
if ( %locked == 1 ) {
if ( $?="This channel is locked, enter your password" != password ) {
echo -a Invalid password entered
halt
}
set %locked 0
echo -a Channel unlocked
}
}

Just added an extra $ by accident frown