Need help with making a password circuit + writing code

So, I decided to try to make a basic password circuit (image included), with 4 buttons and 2 LEDs: a green one that's supposed to turn on if the passcode was entered correctly and a red one that's supposed to turn on if the passcode wasn't entered correctly. You get the idea. I am pretty new to this stuff, and I decided to use the Passcode library (Arduino Playground - Password Library).

Here is the code I have so far (probably lots of mistakes, could you please tell me what I need to do?):
#include <Password.h>

const int key1 = 7;
const int key2 = 6;
const int key3 = 5;
const int key4 = 4;

int key1State;
int key2State;
int key3State;
int key4State;

const int greenLed = 3;
const int redLed = 2;

Password password = Password("1234");

void setup(){
Serial.begin(9600);

pinMode(key1, INPUT);
pinMode(key2, INPUT);
pinMode(key3, INPUT);
pinMode(key4, INPUT);

pinMode(greenLed, OUTPUT);
pinMode(redLed, OUTPUT);

}

void loop(){
key1State = digitalRead(key1);
if (key1State == HIGH) {
password.append('1');
}
key2State = digitalRead(key2);
if (key2State == HIGH) {
password.append('2');
}
key3State = digitalRead(key3);
if (key3State == HIGH) {
password.append('3');
}
key4State = digitalRead(key4);
if (key4State == HIGH) {
password.append('4');
}

Serial.println(password.evaluate()?"true":"false");
password.reset();
}

I have included an image of the circuit and what I want to know is:
-Do I need the Passcode library to do this? Is there a better way?
-What have I done wrong?
-How to I get the LEDs to turn on when I want them to?
Also, Windows plays the sound for when a USB device is unplugged every time I press the buttons. Does it have anything to do with the circuit?

Thank you for your time,
TheChorizo

So, I decided to try to make a basic password circuit

A password is a software concept.

You don't have resistors on the switches, so they are floating. Use the internal pullup resistors, so that pressed is LOW, or add external resistors.

loop() doesn't wait for switches to be pressed. Resetting the password instance on every pass through loop is not a good idea.

What if the password is 1, 2, 3, 4, and you press 1, 2, and 2 accidentally. You don't have a reset or backspace plan.

You should do something more than print true or false, based on the return value from evaluate().

You need to debounce the switches and append to the password when a key state changes.

Thank you for responding!
I have now debounced the switches, but I dont know what to do with the code. I have some experience with C++, but I am still learning to use the Arduino (and this library).
First of all, how do I use the evaluation function to turn on/off the LEDs? And when I added a serial print for when I pressed a button it didn't work? Does it have anything to do with the fact that I had to make it append when the switch state changes? If so, how do I do that?
Thank you so much!

First of all, how do I use the evaluation function to turn on/off the LEDs?

if(password.evaluate())
{
   // turn one led on and the other off
}
else
{
   // turn the other led on and the first one off
}

And when I added

So, you modified your hardware and your software, and posted no new pictures OR code. I see.

it didn't work?

You're asking us? Send me the hardware, and I'll have a look. I'm sure I can tell whether it printed anything, or not.

Here is the new code, and now it seems to work, at least the button thingy. I tried pushing the buttons and I recieved an output the way I wanted. But I seem to have done something wrong with the passcode. What have I missed? The only thing that happens even though I press button 1, 2, 3, 4 in order is that the red LED is turned on. It turns on when I plug in the Arduino board. What have I missed? (I don't have access to a camera right now, so I can't send you a picture of the board. All I did was adding a 100k ohm resistor between the cathode of the button and ground)

#include <Password.h>

const int key1 = 7;
const int key2 = 6;
const int key3 = 5;
const int key4 = 4;

int key1State;
int key2State;
int key3State;
int key4State;

const int greenLed = 3;
const int redLed = 2;

Password password = Password("1234");

void setup(){
Serial.begin(9600);

pinMode(key1, INPUT);
pinMode(key2, INPUT);
pinMode(key3, INPUT);
pinMode(key4, INPUT);

pinMode(greenLed, OUTPUT);
pinMode(redLed, OUTPUT);
}

void loop(){
key1State = digitalRead(key1);
if (key1State == HIGH) {
password.append('1');
Serial.println("1");
}
key2State = digitalRead(key2);
if (key2State == HIGH) {
password.append('2');
Serial.println("2");
}
key3State = digitalRead(key3);
if (key3State == HIGH) {
password.append('3');
Serial.println("3");
}
key4State = digitalRead(key4);
if (key4State == HIGH) {
password.append('4');
Serial.println("4");
}

if(password.evaluate())
{
// turn one led on and the other off
digitalWrite(greenLed, HIGH);
digitalWrite(redLed, LOW);
delay(500);
digitalWrite(greenLed, LOW);
password.reset();
}
else
{
// turn the other led on and the first one off
digitalWrite(greenLed, LOW);
digitalWrite(redLed, HIGH);
delay(500);
digitalWrite(redLed, LOW);
password.reset();
}
}

I am not from an English speaking country so forgive me if I spelled or wrote something wrong.

What does your serial output look like?

You really should look at the state change detection example, to deal with when a pin BECOMES high, not IS high.

Ok, but how do I do that check for a button state change?
This is my serial output:
1
2
3
4
3
2
1
(it just displays the number of the button when it "gets HIGH" (pressed).

Look at what you do if the password evaluates correctly. Look at what you do if it doesn't. Are you doing something if it doesn't that you shouldn't be doing? (The answer is yes. See if you can figure out what that is.)

I guess the password shouldn't reset when I type in the wrong passcode? (It is currently 01:02 in the morning over here in Sweden, so I can't concentrate correctly). But the problem is that I am not sure if it evaluates it correctly when I type in the correct password. The green LED never turns on.
Thanks for helping out!

Edit: Now, when I click the buttons in the right order, the green LED turns on when I hold the last button. What do I have to do to make the red LED stay off until I enter the wrong passcode, and then turn on? And what do I have to do to make the green LED turn on and stay on for some time when I enter the right passcode, without me having to hold the last button?

Edit #2: Finally got it working! Thank you for your help and time! I am really grateful. Thanks!

Now that you got it working, you can start making it more efficient.

If you want, you can make this part

key1State = digitalRead(key1);
if (key1State == HIGH) {
password.append('1');
Serial.println("1");
}
key2State = digitalRead(key2);
if (key2State == HIGH) {
password.append('2');
Serial.println("2");
}
key3State = digitalRead(key3);
if (key3State == HIGH) {
password.append('3');
Serial.println("3");
}
key4State = digitalRead(key4);
if (key4State == HIGH) {
password.append('4');
Serial.println("4");
}

into a FOR loop. If the button is high, return the index.
Now this would mean you would need to reverse these,

const int key1 = 7;
const int key2 = 6;
const int key3 = 5;
const int key4 = 4;

so that all you would need to do is subtract 3 from the index to get what button was pressed.

Yeah, that's probably a good idea. But first, this is the code I currently have and it works great:
#include <Password.h>

const int key1 = 7;
const int key2 = 6;
const int key3 = 5;
const int key4 = 4;

int key1State = 0;
int key2State = 0;
int key3State = 0;
int key4State = 0;

int lastKey1State = 0;
int lastKey2State = 0;
int lastKey3State = 0;
int lastKey4State = 0;

const int greenLed = 3;
const int redLed = 2;

int keyPushCounter = 0;

Password password = Password("1324");

void setup(){
Serial.begin(9600);

pinMode(key1, INPUT);
pinMode(key2, INPUT);
pinMode(key3, INPUT);
pinMode(key4, INPUT);

pinMode(greenLed, OUTPUT);
pinMode(redLed, OUTPUT);
}

void loop(){
key1State = digitalRead(key1);
if (key1State != lastKey1State) {
password.append('1');
Serial.println("1");
keyPushCounter++;
Serial.println(keyPushCounter);
delay(200);
}
key2State = digitalRead(key2);
if (key2State != lastKey2State) {
password.append('2');
Serial.println("2");
keyPushCounter++;
Serial.println(keyPushCounter);
delay(200);
}
key3State = digitalRead(key3);
if (key3State != lastKey3State) {
password.append('3');
Serial.println("3");
keyPushCounter++;
Serial.println(keyPushCounter);
delay(200);
}
key4State = digitalRead(key4);
if (key4State != lastKey4State) {
password.append('4');
Serial.println("4");
keyPushCounter++;
Serial.println(keyPushCounter);
delay(200);
}
if (keyPushCounter >= 4){
if(password.evaluate())
{
// turn one led on and the other off
digitalWrite(greenLed, HIGH);
delay(1000);
digitalWrite(greenLed, LOW);
password.reset();
Serial.println("Correct");
}
else
{
// turn the other led on and the first one off
digitalWrite(redLed, HIGH);
delay(1000);
digitalWrite(redLed, LOW);
password.reset();
Serial.println("False");
}
keyPushCounter = 0;
}
}

When I added a pushcounter (keyPushCounter) I could easily control when to evaluate the entered password, turn on/off the LEDs and when to reset the password. Thank you all for your help, this community is great!