Lock and switch programming question

I am building a box that is supposed to unlock (through a solenoid) when a voltage comes through an analog pin on the Arduino. To ensure the solenoid doesn't close until the door of the box is closed I am using a switch to stop that. The switch should be open until the solenoid = high. This is the code I have written so far (the parts involving the locks and switch): any suggestions

while (lock)
{ //if a key was clicked
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Shut door.");
if (lock == 'A' && digitalRead(doorSwitch) == LOW); //switch is low when it is closed
digitalWrite(solenoidPin, LOW); //lock box
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Box Locked!"); //let user box is locked
lcd.setCursor(0,1);
lcd.print("See u later!");

return;
}

void CheckCodes()
{
while(pin1==pin5 && pin2==pin6 && pin3==pin7 && pin4==pin8){ //check if the codes are equal
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Box Unlocked"); //print that the box is open
lcd.setCursor(0,1);
lcd.print("Retrieve keys.");
digitalWrite(solenoidPin, HIGH); //unlock the box
}

while(pin1!=pin5 || pin2!=pin6 || pin3!=pin7 || pin4!=pin8){ //if one of the pins is NOT equal
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Code Error.");
digitalWrite(solenoidPin, HIGH); //keep box locked
EnterPin5(); //take them back to function to re enter code
}
}

EDIT: maybe a better question would be how would I stop the solenoid from closing before the switch is open. Using an analogwrite. I need the switch to be pressed before the solenoid can lock.
I think I have the right idea below for the solenoid and the analog value but I don't know how to incorporate the switch

void loop() {
val1 = (analogRead(analogBLACK) - analogRead(analogGREEN));

if (val1 >= 100)
{
lcd.setCursor(0,0);
lcd.print("Sober!");
delay(500);
lcd.clear();
analogWrite(solenoidPin, HIGH); //unlock the box

First LCD need libraries i think so . second you better use `` .........

while (lock)
   { //if a key was clicked
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Shut door.");
    if (lock == 'A' && digitalRead(doorSwitch) == LOW); //switch is low when it is closed
    digitalWrite(solenoidPin, LOW); //lock box
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Box Locked!"); //let user box is locked
    lcd.setCursor(0,1);
    lcd.print("See u later!");
   
    return;
   }

The if statement has a body of ;. So, if the statement is true, do nothing. If it is false, do nothing. There is no point in having the if statement.

It is dumb to use a while statement and force it to iterate exactly once. That is what an if statement is for.

It is pointless to post snippets of code. Post ALL of your code.

The variables named pinN imply that they hold pin numbers, not pin states. It is silly to compare pin numbers in an if statement.