Password protected system

hellow everyone
im trying to make a password protected system with servo motor and 4x4 keypad
the code works 100%
i want to assign a specific button to reset the password or delete a digit but i dont know how or where to write the code
it would be very fantastic if someone can help.

#include <Keypad.h>
#include <LiquidCrystal.h>
#include <Servo.h>


#define Password_Length 5


Servo myservo;
LiquidCrystal lcd (A0, A1, A2, A3, A4, A5);
int pos = 0;


char Data[Password_Length ];
char Master[Password_Length ] ="1234";
byte data_count = 0, Master_count = 0;


bool Pass_is_good;
bool door = false;


char customKey;
const byte ROWS =4;
const byte COLS =4;
char keys [ROWS][COLS] =
{
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'},
};
byte rowPins [ROWS] = {0,1,2,3,};
byte colPins [COLS] = {4,5,6,7,};
Keypad customKeypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);


void setup()


{ myservo.attach(9, 2000, 2400);
  ServoClose();


  lcd.begin(16, 2);
  lcd.print("Locked Locker");
  loading("Loading");
  //clean
  lcd.clear();
}
void loop()
{if (door == true)
  {customKey = customKeypad.getKey();
  if (customKey == '#')
    {lcd.clear();
  ServoClose();
  lcd.print("Closing Locker");
  delay(1000);
  door = false;
    }
  }
 else open();
}


void loading (char msg[])
{lcd.setCursor(0, 1);
lcd.print(msg);


for (int i  =  0; i<9; i++)
  {
  delay(300);
  lcd.print(".");
  }
}


void clearData()
{while (data_count != 0)
  {Data[data_count--] = 0;}
return;
}


void ServoClose()
{for (pos =90; pos>= 0; pos -=10)
  {myservo.write(pos);}
}


void ServoOpen()
{for (pos =0; pos<= 90; pos +=10)
  {myservo.write (pos);}
}


void open()
{
  lcd.setCursor(0, 0);
  lcd.print("Enter Password");
  customKey = customKeypad.getKey();
  if (customKey)
  {
    Data[data_count] = customKey;
    lcd.setCursor(data_count, 1);
    lcd.print(Data[data_count]);
    data_count++;
  }
  if (data_count == Password_Length - 1)
  {
    if(!strcmp(Data, Master))
    {
      lcd.clear();
      ServoOpen();
      lcd.print("Enter Inside!");
      door = true;
      delay (3000);
      loading("Wait");
      lcd.clear();
      lcd.print("Times Up!");
      delay(1000);
      ServoClose();
      door = false;
    }
    else
    {
      lcd.clear();
      lcd.print("Go Away!");
      door = false;
    }
    delay(1000);
    lcd.clear();
    clearData();
    }
  }

how safe is it going to be if anyone can press the button and set up a new password?

your code needs to have some sort of master password (using the keypad) that is used to enter admin mode where you can change the password. Of course this password needs then to be saved in EEPROM for the next time you boot so you should read about the EEPROM library too.

as you'll manage different states for your code (locked, unlocked, admin mode, ...) you might benefit from studying state machines. Here is a small introduction to the topic: Yet another Finite State Machine introduction

OK you'll be the one defending this. As this is for an exam, we'll expect to see your attempt at coding this and we'll help along, but we can't do it for you.

Which Button (could it be '*'?) you want to press to reset the Password? What will be the new 4-digit password?

Start by writing down - in detailed steps - what exactly you want the code to be doing.

If a key is pressed: store the input - where? How? What to do with this stored value, if anything?

Reset password - I guess you mean "start keying it in all over again"? Then you will also be doing something to the already received input.

Another resource is a simulator...

... and ask your group members to use one resource (one question, one user), rather than asking the same question on different topics.

@othmangha

"tbh it doesnt matter for me if its secure or no i just want to pass the project and get my exam points i just want to know what code do i have to add to assign a a specific button to be able to reset or restart the password."

Do you pass the class if this is done, or do we?

i apologize on behalf of my friends rudeness i will make sure to report to the teacher about his behavior

1 Like

your teacher is likely checking the forum...

Im dying a little looking at the use of every kind of case in first posts code
Pascal case
Camel case
Snake case
Random case

You knew them all when you started?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.