: I'm having trouble matching the encryptedPass to userPass coz I
: can't use "password" inside the code, but I've encrypted the
: userPass and a 3rd one that is an encrypted version of "password"
: and they match fine.
:
: The only thing i can think of is that i need to use an escape
: character to make ÛÕε¸·"Z usable in the strcpy() so it's ÛÕε¸·\"Z
:
:
:
: int i = 1;
: char *userPass;
: char encryptedPass[20];
: char testPass[20];
:
: strcpy(encryptedPass,"ÛÕε¸·\"Z");
: strcpy(testPass,"password");
: encrypt(testPass,strlen(testPass));
:
: while(i < 4){
: if(i < 3)
: printf("\nAttempt %d\n", i);
: else
: printf("\nLast attempt!\n");
:
: userPass = getpass("Enter password: ");
: encrypt(userPass,strlen(userPass));
: //encrypt(testPass,strlen(testPass));
: // This ^^^ should be moved out of loop
:
:
: if(memcmp(userPass,encPass,8) == 0)
: return;
:
: i++;
: }
: :
There are few more problems: the memcmp() uses 8 as a length, but if user enters a password of 6 chars - then the check may fail in some cases.
The pseudo-code of this looks like this:
char correctPass [20];
char enteredPass [20];
int lenCorrectPass;
int nAttempts = 3;
int bMatch = 0;
strcpy (correctPass, "password");
lenCorrectPass = strlen (correctPass);
encrypt (correctPass, lenCorrectPass);
while (nAttempts--)
{
// read the text from user into 'enteredPass'
encrypt (enteredPass, strlen (enteredPass));
if (memcmp (enteredPass, correctPass, lenCorrectPass) == 0)
{
bMatch++; break;
}
}
if (! bMatch) printf ("\n\nUnable to login after 3 attempts!");
else printf ("\n\nCongrats! You are logged in!");