Project showcase
Logical Password Sequence

Logical Password Sequence © GPL3+

8-digit password sequence program with situational logic.

  • 4,745 views
  • 3 comments
  • 12 respects

Components and supplies

Ph a000066 iso (1) ztbmubhmho
Arduino UNO
Arduino UNO microcontroller for the programming
×1
Tegg 3x4 Keypad
Similar keypad I used in this project
×1
KEYESTUDIO 1602 LCD with I2C backpack
16x2 LCD Display with the I2C backpack
×1

About this project

MY IDEA

I wanted to come up with a password sequence program for a future engineering project I will be putting together to use in a film production. The password is an 8-digit string. I needed the program to be able to accomplish these conditions:

1. If the user tries to type in and enter less than the required 8 digits, the program returns an invalid response and requests you try to enter the password again.

2. If the user tries to type in and enter more than the required 8 digits, the program will do nothing and instead wait for the user to either press the CLEAR or ENTER buttons.

3. If the user wants to clear what they have typed in without having to go through the process of entering an incorrect password in order to start from the beginning, they can easily press the CLEAR button to quickly start over again.

4. Once the password has been entered, the program will either accept the password and grant access, or reject the password and deny access.

After researching other program codes and learning about how functions and keypad integrations work, I was able to write up a fairly intermediate program that addresses these issues.

THE PROGRAM

The program makes use of three libraries: Keypad, Wire, and LiquidCrystal_I2C which need to be downloaded and installed before using this program.

The program allows you to modify the password input to what ever you desire and includes a couple of optional placeholder functions in case you wish to expand on the program.

There are also comments in the program code that describes what a particular line of code is and does.

The keypad setting in the code has been configured for a 4X3 keypad that has a "CLEAR" button in place of an "*"(asterisk) and an "ENTER" button in place of a "#"(hashtag).

You can use almost any keypad whether it be 4x3 or 4x4 but you will need to modify the "Keypad Configuration" section with the specifications that your keypad may have.

HOW IT WORKS

When you enter an 8-digit password string, the moment you hit that 8th digit is when the program switches to another function that checks and compares the string to the master password string. This compare sub-function only accepts one of two key press options: CLEAR to clear the password string array and start the program over from the beginning, or ENTER which enters the password string into the compare code. The numbered keys are disabled in this function.

If the user input password string matches the master string, the programs returns an "ACCESS GRANTED" message. If the user input password string does not match the master string, the program returns an "ACCESS DENIED" message.

At any time, you may press the CLEAR button to run a function that clears all the array data and starts over from the beginning.

In the event the user tries to enter a password string that is less than 8 digits, the program will turn an "INVALID ENTRY" message and start the program over.

Have fun with this code, feel free to use it anywhere, modify it to your hearts' desire. ENJOY!!

Code

PasswordLogicProgram.inoArduino
Program code. Modify to your needs. Have fun with it!
// Program written by Dan Hostler, August 2020.
// Feel free to use as you need to.
// PayPal donations appreciated at danhostler1985@yahoo.com




// LIBRARIES. (PLEASE INSTALL THESE LIBRARIES IF YOU HAVE NOT YET)
#include <Wire.h>               // deals with I2C connections
#include <LiquidCrystal_I2C.h>  // activates the LCD I2C library
#include <Keypad.h>             // activates the Keypad library




// VARIABLES FOR THE 8-NUMBER PASSWORD INPUT DATA
#define Password_Length 9                    // Amount of digits plus one null character (8 + 1 = 9) defines password length
char userInput[Password_Length];             // This variable will store the user input in a string
char Master[Password_Length] = "12345678";   // This variable holds the correct password that the user string must match, change as needed
char customKey;                              // This variable holds key input of every key pressed
byte pressCount = 0;                         // This variable holds a counter for the amount of times the keys were pressed




// KEYPAD CONFIGURATION (PLEASE MODIFY THIS SECTION IF YOUR KEYPAD WIRING IS DIFFERENT FROM BELOW)
const byte ROWS = 4; // Constants for row and 
const byte COLS = 3; // column size of your keypad.

char twelveKeys[ROWS][COLS] =                     // Physical layout of the keypad being used in this program
{ 
    {'1', '2', '3'}, 
    {'4', '5', '6'},
    {'7', '8', '9'},
    {'C', '0', 'E'} // C = CLEAR, E = ENTER
};

byte rowPins[ROWS] = {9, 8, 7, 6};  // Defines how rowPins are connected on the Arduino to the keypad: 9 = R1, 8 = R2, 7 = R3, 6 = R4
byte colPins[COLS] = {5, 4, 3};     // Defines how colPins are connected on the Arduino to the keypad: 5 = C1, 4 = C2, 3 = C3, 2 = C2 (if you have a 4x4 keypad) 




// OBJECT CONFIGURATIONS
Keypad customKeypad = Keypad(makeKeymap(twelveKeys), rowPins, colPins, ROWS, COLS); // Creates keypad "object"
LiquidCrystal_I2C lcd(0x27, 16, 2);                                                 // Creates LCD "object" (I2C address, rows, columns)




// PROGRAM SETUP
void setup() {

  // LCD Initialization
  lcd.backlight(); 
  lcd.init();
  lcd.clear();

}




// MAIN PROGRAM LOOP
void loop() {

  lcd.setCursor(0,0);
  lcd.print(" Type Password:");                                       // One space is offset to center the text on the LCD
  customKey = customKeypad.waitForKey();                              // Program will halt here until a key is pushed

  if (customKey != NO_KEY && customKey != 'C' && customKey != 'E')    // If the user presses the number keys, the data is entered
  {
  userInput[pressCount] = customKey;                                  // Password string is being collected by the userInput variable
  lcd.setCursor(pressCount + 4, 1);                                   // Four is added to pressCount to center the input on the LCD
  lcd.print("*");                                                     // Asterisks are printed for confidentiality 
  pressCount++;                                                       // Key press count will roll over until 8 digits are entered
  }

  else if (customKey == 'C')    // C is to clear the entire password input from any point and start over again as
  {                             // it calls up the clearData function.
  lcd.clear();
  clearData(); 
  }

  else if (customKey == 'E')    // If less than 8 digits are entered, the input will be invalid and 
  {                             // an error message will flash, then call the clearData function to
  lcd.clear();                  // start the entering process all over again.
  lcd.setCursor(0,0);
  lcd.print("INVALID ENTRY");
  delay(800);
  clearData();
  }

   
  if (pressCount == 8)         // Once 8 digits are entered, the function to check the password string is called up and
  {                            // both the character and string data are sent to the function.
  lcd.clear();
  waitHere();                  
  }

}


// THIS FUNCTION CHECKS THE PASSWORD STRING
void waitHere(){

  lcd.setCursor(0,0);
  lcd.print(" Type Password:"); 
  lcd.setCursor(0,1);
  lcd.print("    ********");                    // Password data is hidden as asterisks for confidentiality purposes and
                                                // is offset by 4 spaces to center the input on the LCD
                                                 
  customKey = customKeypad.waitForKey();        // Program will halt here until a key is pushed
  
  if (customKey != NO_KEY && customKey == 'E')  // The ENTER button is pushed and the password goes through the routine.
  {
  lcd.clear();
  lcd.setCursor(0,0);
    if (!strcmp(userInput, Master))             // The user input string is matched up with the Master password string and matches up
    {                                           // running the routine to grant access before returning back to the beginning.
    lcd.setCursor(0,0);
    lcd.print("ACCESS GRANTED.");
    lcd.setCursor(0,1);
    lcd.print("WELCOME!!");
    delay(5000);
    clearData(); 
    }
    else if (strcmp(userInput, Master))         // The user input string is matched up with the Master password string and does not match up
    {                                           // running the routine to deny access before returning back to the beginning.
    lcd.setCursor(0,0);
    lcd.print("ACCESS DENIED.");
    delay(2000);
    clearData(); 
    }
  }

  if (customKey != NO_KEY && customKey == 'C')  // If the CLEAR button is pushed, the data is cleared and the program starts over.
  {
  lcd.clear();
  clearData(); 
  }
  
  if (customKey != NO_KEY && customKey == '0')  // This numberical button has no purpose and does nothing when pressed.
  {
  waitHere();
  }

  if (customKey != NO_KEY && customKey == '1')  // This numberical button has no purpose and does nothing when pressed.
  {
  waitHere();
  }

  if (customKey != NO_KEY && customKey == '2')  // This numberical button has no purpose and does nothing when pressed.
  {
  waitHere();
  }

  if (customKey != NO_KEY && customKey == '3')  // This numberical button has no purpose and does nothing when pressed.
  {
  waitHere();
  }

  if (customKey != NO_KEY && customKey == '4')  // This numberical button has no purpose and does nothing when pressed.
  {
  waitHere();
  }

  if (customKey != NO_KEY && customKey == '5')  // This numberical button has no purpose and does nothing when pressed.
  {
  waitHere();
  }

  if (customKey != NO_KEY && customKey == '6')  // This numberical button has no purpose and does nothing when pressed.
  {
  waitHere();
  }

  if (customKey != NO_KEY && customKey == '7')  // This numberical button has no purpose and does nothing when pressed.
  {
  waitHere();
  }

  if (customKey != NO_KEY && customKey == '8')  // This numberical button has no purpose and does nothing when pressed.
  {
  waitHere();
  }

  if (customKey != NO_KEY && customKey == '9')  // This numberical button has no purpose and does nothing when pressed.
  {
  waitHere();
  }
  
}




// OPTIONAL FUNCTIONS TO USE IN CASE YOU WISH TO EXPAND OUT YOUR PROGRAM
//void accessGranted(){
//  
//}
//
//void accessDenied(){
//  
//}




// CLEARS THE ARRAY DATA, STARTS PROGRAM ALL OVER AGAIN
void clearData() {  
  while (pressCount != 0) 
  {
  userInput[pressCount--] = 0;    // Clears out the user input data, both digit and string data are reset to zero.
  }
  setup();                        // Returns program back to the beginning
}

Schematics

Schematic for project setup
This schematic utilizes a 4x4 keypad but you can easily use a 4x3 keypad by negating pin 2.
Passwordlogicprogram bb woln7z3xmj

Comments

Similar projects you might like

Motion Sensing Alarm With Keypad & Password

Project showcase by thehack904

  • 34,434 views
  • 78 comments
  • 79 respects

Rotary Dial Disk (Rotary Phone) Password programmed

Project tutorial by Aws_Alkarmi

  • 1,833 views
  • 6 comments
  • 16 respects

Arduino and Android Based Password Protected Door Lock

Project tutorial by Md. Khairul Alam

  • 25,373 views
  • 9 comments
  • 64 respects

Arduino - Remotely Open Door via Web with Pattern Password

Project tutorial by phpoc_man

  • 5,956 views
  • 0 comments
  • 23 respects

Secure Your Home by a Password

Project tutorial by يمنى السيد ندا

  • 3,323 views
  • 0 comments
  • 3 respects

Automated Password Typer

Project showcase by mPelectronic

  • 20,369 views
  • 30 comments
  • 47 respects
Add projectSign up / Login