Solved

passwords

Posted on 1998-12-03
2
186 Views
Last Modified: 2010-04-02
HeLp PleeZ...
I'm supposed to create a password (but I've already figured that part out because it could be hard coded; that is, all the passwords are made before hand, no new passwords will  be made during the running of the program, though if U have a suggestion of how to do that, I wouldn't mind the tip at all).  The problem is that I have NO idea of how U would go about finding the matching password.  Say for example, the user types in a random number as his password, the next step would be for the program to look if there are any matches....and that's where my problem comes in...how could I go about creating my program to look for matches??
0
Comment
Question by:Marian111998
2 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 20 total points
ID: 1179153
Suppose your passwords were stored in an array

char *Passwords[MAXPASSWORDS];

Then to find if a password matches the known ones you could do this:

int FindPassword(char *ThePassword)
{
  int i;

  for (i = 0; i < NumPasswords; i++)
  {
    if strcmp(ThePassword, Passwords[i])
    {
      return TRUE;
    }
  }

  return FALSE;
}

You can trivially alter this code to use any data structure you please to hold the passwords...

Cheers,

Raymond.

0
 
LVL 11

Expert Comment

by:alexo
ID: 1179154
[Beat by Raymond, submitting as comment]

If you want to keep the passwords as plain text, you can use something like:

    int match(char* string)
    {
        static char* passwords[] = { "first", "second", "third" };
        int i;

        for (i = 0; i < sizeof(passwords) / sizeof(*passwords); ++i)
            if (strcmp(string, passwords[i]) == 0)
                return 1; /* found a match */

        return 0; /* no match found */
    }

If you want to keep the passwords encrypted, first encrypt the string and then call the match() function.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

810 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