Shop OBEX P1 Docs P2 Docs Learn Events
New guy, need password-type assistance — Parallax Forums

New guy, need password-type assistance

BasicCantBasicCant Posts: 6
edited 2014-02-16 09:52 in Learn with BlocklyProp
Hi everyone,

I searched around the forums and found a lot of incomplete threads that didn't help me too much. I'm pretty new to BS2, and I'm trying to accomplish password storage, and comparison. I am aware of the need for time-outs and other security measures with passwords. I am fairly confident I can work those out on my own once I have the basic password operation working. What I need help with is how to store a string of inputs and compare that to a specified 'correct' string.

I am using a BS2 board and the 4x4 membrane keypad. I have cut out the necessary parts of the keypad example code to begin with. As a reference it is here:
'========= Keypad Password ======================================




password    DATA "1234"
row         VAR  Nib                        ' Variable space for row counting
column      VAR  Nib                        ' Variable space for column counting
keypad      VAR  Word                       ' Variable space to store keypad output
keypadOld   VAR  Word                       ' Variable space to store old keypad output
temp        VAR  Nib                        ' Variable space for polling column states






DEBUG CLS                                   ' Clear Debug Terminal


DO
  GOSUB ReadKeypad                          ' Read keypad button states
  DEBUG HOME, BIN16 keypad, CR, CR,         ' Display 16-bit keypad value
              BIN4 keypad >> 12,CR,         ' Display 1st row 4-bit keypad value
              BIN4 keypad >> 8, CR,         ' Display 2nd row 4-bit keypad value
              BIN4 keypad >> 4, CR,         ' Display 3rd row 4-bit keypad value
              BIN4 keypad                   ' Display 4th row 4-bit keypad value


  keypadOld = keypad                        ' Store keypad value in variable keypadOld
LOOP


' -----[ Subroutine - ReadKeypad ]-------------------------------------------------
' Read keypad button states
ReadKeypad:
  keypad = 0
  OUTL   = 000000                        ' Initialize IO
  DIRL   = 000000


  FOR row = 0 TO 3
    DIRB = 11                            ' Set columns (P7-P4) as outputs
    OUTB = 00                            ' Pull columns low (act as pull down)
    OUTA = 1 << Row                         ' Set rows high one by one
    DIRA = 1 << Row


    temp = 0                                ' Reset temp variable to 0
    FOR column = 0 TO 3
      INPUT (column + 4)                    ' Set columns as inputs one by one
      temp = temp | (INB & (1 << column))   ' Poll column state and store in temp
    NEXT


    keypad = keypad << 4 | (Temp REV 4)     ' Store keypad value






  NEXT
RETURN



My questions are:

Where should I add code to start reading the keypad inputs?

Do I store the 'keypad' value to a second variable? Like concatenate them into a string? How would that work?

Is LOOKUP the best way to compare the strings? How might this look coded?



I'll be watching this thread closely as I need to finish this objective within a day or two. I'll do my best to aid anybody willing to help with follow-ups.


Thankyou in advance, everybody.

Comments

  • BasicCantBasicCant Posts: 6
    edited 2014-02-15 06:31
    Anybody? Do I need to provide more/clearer info?
  • prof_brainoprof_braino Posts: 4,313
    edited 2014-02-15 08:33
    Advice - start earlier, read more in preparation. Sorry, that's best I can do with an unworkable deadline.
  • BasicCantBasicCant Posts: 6
    edited 2014-02-15 08:48
    I appreciate the response. I have been doing all the research I can in the meantime, and I couldn't have started earlier, I started an hour after given the assignment (Fri). I just ran into the issue... there is much more to the project than this, I didn't feel the need to include it though as it doesn't help anybody..

    Disregard the deadline I mentioned, but did you have any input besides advice? This seems like it would be fairly elementary for most members of this board.
  • davejamesdavejames Posts: 4,047
    edited 2014-02-15 11:40
    BC - welcome to the Forum.

    FYI...there are many, many users here that are more than happy to help you out. What we generally don't do as a community is provide a finished project. Showing someone "how to fish" is usually the case.

    Large lists of items to tackle and short time frames are difficult and will most likely not receive much attention.

    That said...

    1) Of the code you posted (and thank you for using the [code] tags), does it work as you expect?
    2) Information on the keypad would be nice
    3) Have you constructed any kind of flow chart, flow diagram to help visualize the end result?
    4) What is your background on the BS2? Newbie, some?

    All this will help formulate a response.
  • kwinnkwinn Posts: 8,697
    edited 2014-02-15 12:25
    First, although I am familiar with several versions of Basic I am not a BS2 user so I will not be much help with specific code for the BS2.

    Second, I am assuming you mean the 4x4 Matrix Membrane Keypad pn 27899. There is example code for the basic stamp at http://www.parallax.com/product/27899. Use that as a starting point.

    In response to your other questions:

    Where should I add code to start reading the keypad inputs?

    A common practice is to have a subroutine that performs all the required functions (scanning, debouncing, key decoding, etc) and returns a code for each valid key press or an error code for multiple or no key-presses. Your main program would call this subroutine when it needs to read a key.

    Do I store the 'keypad' value to a second variable? Like concatenate them into a string? How would that work?

    One way is to read all the numbers and store them in a string variable. Once you have read in and stored all of the characters you compare them to a table of valid passwords to see if there is a match.

    Is LOOKUP the best way to compare the strings? How might this look coded?

    Lookup is one way to compare the strings. Download the Basic Stamp manual and Basic Stamp 2 application notes (links below) for examples and more info.

    http://www.parallax.com/downloads/basic-stamp-manual
    http://www.parallax.com/downloads/basic-stamp-2-app-notes
  • BasicCantBasicCant Posts: 6
    edited 2014-02-15 13:35
    Thanks davejames and kwinn for the responses.

    DJ -

    I respect the "how to fish" approach as mentioned.

    1) Of the code you posted (and thank you for using the [code] tags), does it work as you expect?
    2) Information on the keypad would be nice
    3) Have you constructed any kind of flow chart, flow diagram to help visualize the end result?
    4) What is your background on the BS2? Newbie, some?

    1) Yes the code I posted works. It is the example code from Parallax with the diagram portions removed only.
    2) It is as kwinn assumed, sorry I wasn't more specific. I forget that most users here probably use/fabricate a massive range of products. It is the 4x4 Membrane Keypad found here: http://www.parallax.com/product/27899
    3) I have not created one specific for the keypad operation, I have one for the entire project. But essentially I was thinking:

    - Wait for keypad input
    - Save input (considering the WRITE command to EEPROM)
    - Use "#" input as terminating condition
    - Compare with saved password
    - Conditionals based on correct or incorrect

    4) I have only been experimenting with BS2 for about two months now. I have progressed through the entire Whats A Microcontroller? text.


    kwinn -

    I plan to queue the password-entry action with a subroutine.


    Thanks for the links to those downloads, I'm giving them a read-over now.

    ---

    Anyway, I'll try to ask less open-ended questions. Also, in the above code, I realize the comments wrapped and made things hard to read. Sorry.

    Would it make sense to add a WRITE command into the ReadKeypad subroutine above that would copy the BIN16 value into an EEPROM address? Then I was planning to use READ to call and compare the entries. Is there a conversion process I need to conduct before saving?

    Thanks again for being patient with me. My inexperience with this hardware is making it difficult for me to know how to ask my questions.
  • GenetixGenetix Posts: 1,754
    edited 2014-02-15 13:38
    Look at the code in Chapter #10, Activity #4 of What's a Microcontroller VERSION 2.2
  • BasicCantBasicCant Posts: 6
    edited 2014-02-15 14:01
    Genetix wrote: »
    Look at the code in Chapter #10, Activity #4 of What's a Microcontroller VERSION 2.2

    Thanks Genetix! I had v3.0 and they apparently omitted this. This is certainly helpful.


    Also, I realized the 'keypad' variable will return powers of 2 if converted to decimal. I can use this to identify which key is pressed. All I need to work out now is some sort of loop that stores the 5 consecutive entries into the EEPROM for comparison.
  • kwinnkwinn Posts: 8,697
    edited 2014-02-15 16:36
    BasicCant wrote: »
    Thanks Genetix! I had v3.0 and they apparently omitted this. This is certainly helpful.


    Also, I realized the 'keypad' variable will return powers of 2 if converted to decimal. I can use this to identify which key is pressed. All I need to work out now is some sort of loop that stores the 5 consecutive entries into the EEPROM for comparison.

    Why would you want to store the keypad entries in eeprom? Are these for the table of valid passwords?
  • BasicCantBasicCant Posts: 6
    edited 2014-02-15 16:51
    kwinn wrote: »
    Why would you want to store the keypad entries in eeprom? Are these for the table of valid passwords?

    Yes. Trying to create some code that will write one of the keypresses to a variable, then read it back to the debug window so that I can confirm it stored/reads correctly.

    Then I'll expand on it to store a list of 4 values. And then fit it into a loop so that it will scan continuously for user inputs.

    End result is: I want to send the program into a state that will read keypad entries of 4 digits and confirm it matches a password. There may be simpler ways of doing this than the approach I'm taking, but I am -so far- unaware of them.
  • kwinnkwinn Posts: 8,697
    edited 2014-02-15 20:27
    You need to take this one step at a time. Start with a main program loop that calls the keypad subroutine and sends the resulting key code to the debug terminal.

    Once you have the keypad routine returning the proper code for each key press add a getpassword subroutine that calls the keypad routine four times and stores each code in an array or string. Change the main program loop so it now calls the getpassword routine and sends the resulting key code to the debug terminal.

    Once you have everything up to this point you can continue to add subroutines and calls to perform the rest of the functions you need.
  • kwinnkwinn Posts: 8,697
    edited 2014-02-15 20:52
    BTW You need to post a diagram of how you have the keypad connected to the BS2, including the pin numbers for both the keypad and the BS2. There should be a total of 8 pins, 4 inputs and 4 outputs.
  • GenetixGenetix Posts: 1,754
    edited 2014-02-16 09:52
    First, get the keypad working using the sample programs.

    Next, add the WAM password code (remember the WAM program uses the keyboard)

    Then you expand upon it. It's always best to start with working code and then it modify it to meet your needs.
Sign In or Register to comment.