• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

passwords

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
Marian111998
Asked:
Marian111998
1 Solution
 
rwilson032697Commented:
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
 
alexoCommented:
[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

Technology Partners: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now