Arduino keypad security?

hello,
I am trying to use and arduino and a keypad to replace my old broken garage door opener keypad. I am going to have a relay trip when the correct code is entered in the keypad. One problem though. Once I type in the code, I HAVE to hit clear, otherwise you can just hit enter and get in. any help?

#include <Password.h> 
#include <Keypad.h> 
Password password = Password( "1234" );


int state = 1; //automatically sets to locked state

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};

byte rowPins[ROWS] = {5, 4, 3, 2}; 
byte colPins[COLS] = {8, 7, 6};


// Create the Keypad
int ledpin = 13;
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
pinMode(ledpin, OUTPUT);
  Serial.begin(9600);
  keypad.addEventListener(keypadEvent); 
}

void loop(){
  keypad.getKey();
}

//take care of some special events
void keypadEvent(KeypadEvent eKey){
  switch (keypad.getState()){
    case PRESSED:
	Serial.print("Pressed: ");
	Serial.println(eKey);
	switch (eKey){
	  case '*': checkPassword(); break;

	  case '#': password.reset(); break;
	  default: password.append(eKey);
     }
  }
}

void checkPassword(){
  if (password.evaluate()){
    Serial.println("Success");
   
digitalWrite(ledpin, HIGH);
 delay(500);
digitalWrite(ledpin, LOW);


  }else{
  
  
    Serial.println("Wrong");
   digitalWrite(ledpin, LOW);
  
  }
}
	  case '*': checkPassword();    //  Remove the "break;" here so the password is reset after checking

	  case '#': password.reset(); break;

THANK YOU! this worked and I fell stupid for not realizing that. By the way, I'm only 12 so i guess I'm at a good start anyway. Thanks!

Good work getting that working at the age of 12. Way to go!

zainiak:
THANK YOU! this worked and I fell stupid for not realizing that. By the way, I'm only 12 so i guess I'm at a good start anyway. Thanks!

Excellent start!

Another way to do it would be:

        case '*': 
            checkPassword();
	    password.reset();   // Reset the password after checking
            break;

        case '#': 
            password.reset(); 
            break;

That's how I would have done it if the reset case had not happened to be the next case down. :slight_smile: