Pages: [1]   Go Down
Author Topic: 2 passwords (maybe more)  (Read 519 times)
0 Members and 1 Guest are viewing this topic.
Philippines
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is there a way in the password library that can define 2 passwords? For example, one user will use '1234' as his password and the other user will use 'ABCD'.  This way I can monitor who goes in a certain room. TYVM.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 211
Posts: 13469
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Philippines
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, can you show me how?

I tried the following lines

Password pass1 = Password("1234");
Password pass2 = Password("ABCD");

and in checking, the ff lines

if(pass1.evaluate(){
 //do this
}
if(pass2.evaluate(){
 //do that
}
else{
 //do nothing
}

Pressing the 1234 works. pressing ABCD goes to do nothing. TYVM.
Logged

London
Offline Offline
Full Member
***
Karma: 0
Posts: 168
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've not used that library, but have you tried (re)setting the password in the setup?

Code:
Password pass1 = Password();
Password pass2 = Password();

void setup()
{
  pass1.set("ABCD");
  pass2.set("1234");
}

void loop()
{
  //whatever
}
Logged

Current Projects: Rodentometer - Hamster Endurance Moni

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Pressing the 1234 works. pressing ABCD goes to do nothing.
None of my Arduinos have anything called a 1234 or an ABCD to be pressed. You need to show all of your code, so we have some idea what "pressing the 1234" and "pressing ABCD" mean.
Logged

Philippines
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I finally got it right...
Here's the code as requested.

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

Password pass1 = Password("ABCD");
Password pass2 = Password("1234");
int spkrpin = 9;
int ledpin = 13; //will be use for activating a relay
int ctr = 0; //LCD column counter
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] = {46, 48, 50, 52}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {47, 49, 51, 53}; //connect to the column pinouts of the keypad
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //connect to the LCD pinouts

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
  pinMode(spkrpin, OUTPUT);
  pinMode(ledpin, OUTPUT);
  digitalWrite(ledpin, LOW);
  lcd.begin(16,2);
  keypad.addEventListener(keypadEvent);
  keypad.setDebounceTime(250);
}

void loop(){
  keypad.getKey();
  lcd.setCursor(0,0);
  lcd.print("Type password...");
}

void keypadEvent(KeypadEvent eKey){
   
   switch (keypad.getState()){
     case PRESSED:
   lcd.setCursor(ctr++,1);
        lcd.print(eKey);
   digitalWrite(spkrpin, HIGH);//Makes a clicking
        delayMicroseconds(500);     //sound after pressing
        digitalWrite(spkrpin, LOW); //a key
       
        switch (eKey){
          case '#': guessPassword(); break;
          default: {
            pass1.append(eKey);
            pass2.append(eKey);
          }
  }
 }
}

void guessPassword(){
     lcd.clear();
     lcd.setCursor(0,0);
     lcd.print("Checking ...");
     delay(1000);
     if (pass1.evaluate()){
        lcd.setCursor(0,1);  lcd.print("PASSWORD OK");
             digitalWrite(ledpin,HIGH);
             delay(2000);
             digitalWrite(ledpin,LOW);
             pass1.reset();
             pass2.reset();
     }
     else if (pass2.evaluate()){
        lcd.setCursor(0,1);  lcd.print("PASSWORD OK");
             digitalWrite(ledpin,HIGH);
             delay(2000);
             digitalWrite(ledpin,LOW);
             pass2.reset();
             pass1.reset();
     }
     else{
        digitalWrite(ledpin,LOW);
             lcd.setCursor(0,1);  lcd.print("WRONG PASSWORD");    
        pass1.reset();
             pass2.reset();
     }
     ctr=0;
     delay(3000);
     lcd.clear();
}
Logged

Pages: [1]   Go Up
Jump to: