Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 457
  • Last Modified:

Accepting a password from a keypad input.

Hi, I need to write a program that stores a password...(probably an array stored password). This password will be checked and compared when an input from a keypad is entered. Every thing is done through a micro controller. I got the keypad configuration done. In other words the micro accepts the inputs from the keypad, but my dificulty is creating a program that takes a password from the keypad. Sort of an ATM machine that needs a password from the user to identify and access the card...How could I do that?
Thank you very much
This is the idea I have...but not finished

unsigned char pass[3];
      pass[0] = 0x65; pass[1] = 0x43; pass[2] = 0x21;    // password!

// wait for an iinput from keypad
// compare input from keypad to stored password
// if it is the same then do something...
// else...do it again.
0
caleno
Asked:
caleno
  • 5
  • 4
  • 2
  • +2
1 Solution
 
stefan73Commented:
Hi caleno,
Is this homework?

Cheers,
Stefan
0
 
sunnycoderCommented:
Hi caleno,

man getpass

Sunnycoder
0
 
sunnycoderCommented:
stefan,

It most likely is a part of academic project :o)

Sunnycoder
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
Kent OlsenData Warehouse Architect / DBACommented:

Either that, or he's acquired a new project and is in over his head.  :)

Kent
0
 
calenoAuthor Commented:
Hi, this is project I have at work, and the only part that is giving me dificulty is this password thing.
Can any one help me?
Please
0
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi caleno,

As Sunny suggests, getpass() was designed specifically to handle password input.  If you more flexibility that getpass() provides, you might start with the following:


char SavedPassword[];  /*  Password that the user must match  */

char UserPassword[];   /*  Password that the user is entering  */
int  PasswordLength;
ch   KeyPress;

 PasswordLength = 0;
 while (1)
 {
    KeyPress = getchar ();
    if (KeyPress == '\n')
    {
      UserPassword[PasswordLength] = 0;
      break;
    }
    if (PasswordLength < MaximumPasswordSize)
      UserPassword[PasswordLength++] = KeyPress;
 }
 if (strcmp (SavedPassword, UserPassword) == 0)
   /*  Passwords match  */
 else
   /*  Wrong Password  */



Accepting a password from the keypad is pretty easy stuff.

Good Luck,
Kent
0
 
calenoAuthor Commented:
Kent, I really appreciate your help. I am still learning programming. Since I am using a micro controller with 8K of memory I think I need a lot of flexibility. I will use your sample and try to implement this.
Thanks
0
 
calenoAuthor Commented:
Kent, I have implemented your idea for the solution to my problem. It worked fine but I do not wish to use the  if (strcmp (SavedPassword, UserPassword) == 0) execution code...how else can I compare the contents of the two arrays?
Thanks
0
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi caleno,

I'm completely confused here.  strcmp() is a standard C routine that compares two strings.  There are related function that allow you to compare items without regard of case, or compare memory regions, etc.  All of these may have some application in your project.

strcmp() seems to be the most likely candidate for your use.  It compares the characters in the SavedPassword[] buffer with those that were input.  The key here is that it compares all of the visual characters as well as the zero-terminator, so that the length of the input string is automatically tested along with the contents.

You could compare the two strings, byte by byte, but that would certainly make your source code longer and less clear.

What's your aversion to strcmp()?

Kent
0
 
calenoAuthor Commented:
Kent, when I first tried it, the compiler rejected the strcmp() function. Later I found that I needed a header, directive file .h that was not included in my program. I had to go through the libraries and I found it. Now the program is working fine. I will accept your answer and thanks for your time. I will be posting more questions based on my project. I am not an expert in C programming, but I am more than willing to learn, beacuse I like it.
Take care!
0
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi caleno,

Here's some irony for you --

>>  I am not an expert in C programming, but I am more than willing to learn, beacuse I like it.

I've been programming C for more that 20 years, and still despise it.  It's just that I've written so much C code that I'm proficient with it.  I'd much rather use a language that works harder to protect me from myself, but for a long time there wasn't a commonly accepted language that did that.


Kent
0
 
Avik DasguptaCommented:
Hi,
 which Microcontroller are u using? Is it based on 8085 or some other? Try to use a cross compiler if it is available else for 8085 there are no explicit string handling instructions. U have to place or allign the password in random memory region and compare byte by byte. Do not place the stored password in a particular memory region, it may be hacked.
Suppose
Memory        Data
3000             23
3001             25
3002             47
Ur stored password is from 3000H to 3002H
Now u key in from ur keypad.
23
Store in 4000H
25
Store in 4001H
37
Store in 4002H

Now start comparing contents of
[3000h],[4000h]
Ok
[3001h],[4001h]
Ok
[3002h],[4002h]
Incorrect Password, Key in again !!!!!!!

This was a typical case I discussed.
Avik.
0
 
Avik DasguptaCommented:
I think the answer was accepted during my typing :)

Avik.
0
 
calenoAuthor Commented:
Kent I have been writing code for about a year now. I graduated from EE, and I had to learn some basic programming in C...one or two page programs. Nothing compared to what I am doing now.
Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now