Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

passwords

Posted on 1998-12-03
2
Medium Priority
?
191 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
[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
2 Comments
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 80 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

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!

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

618 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