As you can tell by the code (pasted below), my program is supposed to get the hash as a command line argument, and then prompt the user for a "guess" as to what the plaintext password might be. It then takes the guess, runs it through crypt() and compares the result to the original hash. If they are equal, it's supposed to claim "that's the password", if not, it should let the user know they are not equal.
However, when I test using "./crack 50fkUxYHbnXGw" as the command line arguments, and input "rofl" as the guess, the program claims they are not equal even though when it prints the result it is the exact same as the hash.
I've spent an hour trying to figure this out and I haven't made any headway - I'm hoping someone here can point me in the right direction. I'm sure I'm missing something small.
Code:
int main(int argc, string argv[1])
{
while (argc != 2)
{
printf("This program requires one command line argument to run.");
return 1;
}
// initialize hash to a variable
string hash = argv[1];
// initialize the known salt to an array
char salt[3] = "50";
salt[2] = '\0';
//get a guess
printf("Input guess\n");
string guess = GetString();
// hash the guess using cryptf
string result = crypt(guess, salt);
printf("%s\n", result);
// compare the result to the hash given
if (result == hash) { // if the guess is correct print and exit
printf("%s is the password!\n", guess);
}
else {
printf("Sorry, %s is NOT the password!\n", guess);
}
}
The result of running this program with the aformentioned parameters is:
~/workspace/pset2/crack/ $ ./crack 50fkUxYHbnXGw
Input guess
rofl
50fkUxYHbnXGw
Sorry, rofl is NOT the password!