Solved

Accepting a password from a keypad input.

Posted on 2004-04-19
14
451 Views
Last Modified: 2010-04-15
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
Comment
Question by:caleno
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
  • +2
14 Comments
 
LVL 12

Expert Comment

by:stefan73
ID: 10859689
Hi caleno,
Is this homework?

Cheers,
Stefan
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10859696
Hi caleno,

man getpass

Sunnycoder
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10859704
stefan,

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

Sunnycoder
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 45

Expert Comment

by:Kent Olsen
ID: 10859725

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

Kent
0
 

Author Comment

by:caleno
ID: 10860057
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
 
LVL 45

Accepted Solution

by:
Kent Olsen earned 125 total points
ID: 10860157
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
 

Author Comment

by:caleno
ID: 10860395
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
 

Author Comment

by:caleno
ID: 10861771
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
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 10861922
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
 

Author Comment

by:caleno
ID: 10862284
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
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 10862333
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
 
LVL 2

Expert Comment

by:Avik77
ID: 10862445
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
 
LVL 2

Expert Comment

by:Avik77
ID: 10862470
I think the answer was accepted during my typing :)

Avik.
0
 

Author Comment

by:caleno
ID: 10864757
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question