RFID card reader lock/unlock

Hi
i would like little help with the code below

I want my program when it starts to be armed… but when i pass a knowing RFID card stored in memory the program goes to not armed station (something i have manage to do )

Question :

how to make it with a second pass go to previous stage? to “armed”

with my code below the code after the first pass it is like stores the card like it is always present in RFID reader

#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 5

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance.
String UIDstring;
boolean flaglock = false;
String knownCard = "36166228246";
String knownCard2 = "225197370";



byte redled = 2;
byte greenled = 3;

void setup() {
  
 Serial.begin(9600); 
 SPI.begin();      // Init SPI bus
 mfrc522.PCD_Init(); // Init MFRC522 card
 pinMode(redled, OUTPUT);
 pinMode(greenled, OUTPUT);

}

void loop() {
 
  if (flaglock==false) {
    digitalWrite(redled, HIGH);
    digitalWrite(greenled, LOW);
    Serial.println("Armed");
    delay(500);
  }
    else if (flaglock==true) {
    digitalWrite(redled, LOW);
    digitalWrite(greenled, HIGH);
    Serial.println("NOT Armed");
    delay(500);
  }

card();

}

void card() {


if (! mfrc522.PICC_IsNewCardPresent()) {
    return;
  }
 if (  ! mfrc522.PICC_ReadCardSerial()) {
     return;
  }
  Serial.print("Card UID:");
  UIDstring = "";
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    UIDstring = UIDstring + String(mfrc522.uid.uidByte[i]);
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
  } 
  Serial.println();
  
  Serial.println(UIDstring);
if ((flaglock==false) && (UIDstring == knownCard || UIDstring == knownCard2 )) {
  flaglock = true;
}

/*  // if i place thel lines below, then the code jumps to "armed" like never being in "not armed"  .


if ((flaglock==true) && (UIDstring == knownCard || UIDstring == knownCard2 )) {
  flaglock = false;
}


*/
  
}

Thanks in advance

Ok i find this solution in my problem so i can continue my project.
even though if someone has any other suggestion i would like to hear is as i am new in coding

thanks

#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN 10
#define RST_PIN 5

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance.
String UIDstring;
boolean flaglock = false;
String knownCard = "36166228246";
String knownCard2 = "225197370";



byte redled = 2;
byte greenled = 3;

void setup() {
  
 Serial.begin(9600); 
 SPI.begin();      // Init SPI bus
 mfrc522.PCD_Init(); // Init MFRC522 card
 pinMode(redled, OUTPUT);
 pinMode(greenled, OUTPUT);

}

void loop() {
 
  if (flaglock==false) {
    digitalWrite(redled, HIGH);
    digitalWrite(greenled, LOW);
    Serial.println("Armed");
    delay(500);
  }
    else if (flaglock==true) {
    digitalWrite(redled, LOW);
    digitalWrite(greenled, HIGH);
    Serial.println("NOT Armed");
    delay(500);
  }
if (flaglock==false) {
  card();
}
//card();

if (flaglock==true) {
  card2();
}

}

void card() {


if (! mfrc522.PICC_IsNewCardPresent()) {
    return;
  }
 if (  ! mfrc522.PICC_ReadCardSerial()) {
     return;
  }
  Serial.print("Card UID:");
  UIDstring = "";
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    UIDstring = UIDstring + String(mfrc522.uid.uidByte[i]);
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
  } 
  Serial.println();
  
  Serial.println(UIDstring);
if ((flaglock==false) && (UIDstring == knownCard || UIDstring == knownCard2 )) {
  flaglock = true;
  delay(1000);
  
}

 
  
}


void card2() {


if (! mfrc522.PICC_IsNewCardPresent()) {
    return;
  }
 if (  ! mfrc522.PICC_ReadCardSerial()) {
     return;
  }
  Serial.print("Card UID:");
  UIDstring = "";
  for (byte i = 0; i < mfrc522.uid.size; i++) {
    UIDstring = UIDstring + String(mfrc522.uid.uidByte[i]);
    Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
    Serial.print(mfrc522.uid.uidByte[i], HEX);
  } 
  Serial.println();
  
  Serial.println(UIDstring);
if ((flaglock==true) && (UIDstring == knownCard || UIDstring == knownCard2 )) {
  flaglock = false;
  delay(1000);
 
}


  
}