Solved

passwords

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
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 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 learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

691 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