Solved

passwords

Posted on 1998-12-03
2
184 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

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…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

762 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now