Password Lib evaluate

Hello,
I am using the password lib(Click Here) and I am having trouble with the password evaluation.

#include <Password.h>
Password password = Password( "12341234" );
int buzzerPin = 6;
int unlockPin = 7;
int onePin = 3;
int twoPin = 2;
int threePin = 5;
int fourPin = 4;
int keyPadVal = 0;
boolean logon = false;
void setup() {
  pinMode(buzzerPin, OUTPUT);
  beep(300);
  beep(300);
  beep(300);
  Serial.begin(9600);
  pinMode(onePin, INPUT);
  pinMode(twoPin, INPUT);
  pinMode(threePin, INPUT);
  pinMode(fourPin, INPUT);
  
  
  
  

}

void loop() {
  if (logon == true){
    
  }
  else{
  if (digitalRead(onePin) == HIGH){
    password.append("1");
    Serial.println(1);
    beep(100);
  }
  if (digitalRead(twoPin) == HIGH){
    password.append("2");
    Serial.println(2);
    beep(100);
  }
  if (digitalRead(threePin) == HIGH){
    password.append("3");
    Serial.println(3);
    beep(100);
  }
  if (digitalRead(fourPin) == HIGH){
    password.append("4");
    Serial.println(4);
    beep(100);
    
  }
  if (password.evaluate() == true && digitalRead(unlockPin) == HIGH){
    logon = true;
    beep(500);
    beep(500);
  }
  if (password.evaluate() == false && digitalRead(unlockPin) == HIGH){
    password.reset();
    beep(1000);
    beep(1000);
  if (password == NULL && digitalRead(unlockPin) == HIGH){
    beep(300);
      
  }
  }
  else{
  }
      
    }
  }
    
  
  
  
  
  


void beep(int buzzerTime){
  digitalWrite(buzzerPin, LOW);
  delay(buzzerTime);
  digitalWrite(buzzerPin, HIGH);
  delay(buzzerTime);
  
  
}

I have included the whole script for you to see but the main issue lies with the following:

if (password.evaluate() == true && digitalRead(unlockPin) == HIGH){
    logon = true;
    beep(500);
    beep(500);
  }
  if (password.evaluate() == false && digitalRead(unlockPin) == HIGH){
    password.reset();
    beep(1000);
    beep(1000);
  if (password == NULL && digitalRead(unlockPin) == HIGH){
    beep(300);

For some reason, whenever I activate unlockPin, the arduino will always evaluate the password as false. I know that my password entered is right because of my serial monitor telling me so(I have a 1-2-3-4 numberpad).

Can anyone tell me why it always evaluates to false?

So the Serial Monitor says 12341234, just like your password? Are you getting any beeps to indicate unexpected events?

When you activate the unlock pin, by whatever means you do that, you call password.evaluate(). You do that regardless of whether or not you have completed entering the password.

If you haven’t, eveluate() is going to return false. When it does that, you reset the password to empty.

Is that what you REALLY want to be doing?

To answer some questions:

So the Serial Monitor says 12341234, just like your password? Are you getting any beeps to indicate unexpected events?

Yes, the serial monitor shows: 1 2 3 4 1 2 3 4

And i get a beep after each button I press

When you activate the unlock pin, by whatever means you do that, you call password.evaluate(). You do that regardless of whether or not you have completed entering the password.

If you haven't, eveluate() is going to return false. When it does that, you reset the password to empty.

I can tell from the serial monitor that my passsword was entered as 12341234.

I want to create a state so that as seen in the program from my first post it changes a variable that the loop sees and begins to loop through a different part than the password(i realized I could have used a switch func but whatever.) Also about the password reset I know when it resets when I hear 2 one-second beeps.

I think I see a possible cause of the problem. Your code uses:    password.append("3"); while the example code in the library description uses password.append('3');//add 3 to the guessed password The example passes a character constant and you pass a string constant. Try changing the double-quotes to single-quotes.

You also need to stop resetting the entered password whenever you evaluate it, and they don't match.

You enter '1', and compare "1" to "12341234". They don't match, so you clear the entered password.

You enter '2', and compare "2" (NOT "12") to "12341234". They don't match, so you clear the entered password.

You enter '3', and compare "3" (NOT "123") to "12341234". They don't match, so you clear the entered password.

You will never, the way you have the code written now, get the password to compare to be "12341234".

PaulS: You also need to stop resetting the entered password whenever you evaluate it, and they don't match. You enter '1', and compare "1" to "12341234". They don't match, so you clear the entered password.

  if (password.evaluate() == false && digitalRead(unlockPin) == HIGH) {
    password.reset();
    beep(1000);
    beep(1000);
  if (password == NULL && digitalRead(unlockPin) == HIGH){
    beep(300);
  }
  }

The evaluation is done but only acted on if the button pin is HIGH (I assume that means Pressed) so the password is not reset unless someone presses the UNLOCK button without putting in the right password. Yes, there is an if-statement imbedded in that if-statement that looks like it should be separate (or non-existant) but that should not cause a false reset.

You also need to stop resetting the entered password whenever you evaluate it, and they don't match.

Yes but if I press 12341234 on my numberpad it wont reset untill I evaluate. Thanks for the help with the "" vs '', I am also a python programmer and in that language "" is the same as ''. I will make a post within an hour or two when I test it as I am currently not home.

Ok so it is working now. I had to append using ('1') not ("1") thanks to johnwasser! It will reset if the password if you push the button and get it wrong, and go through the code I am adding if you get it right and stop looping for the input. Thanks again for the help