void checkPass(char* hashFile, char* tempString, int myRank, char* type) { int i; bool foundPass = false; char str[SHA256_HASH_LENGTH+1]; char testHash[SHA256_HASH_LENGTH+1]; if (strcmp(type, "MD5") == 0) { sprintf(testHash, "%s", md5.digestString(tempString)); } else if (strcmp(type, "SHA1") == 0) { unsigned char binaryHash[SHA_DIGEST_LENGTH]; unsigned char* sha1String = (unsigned char*)tempString; SHA1(sha1String, strlen(tempString), binaryHash); for (i = 0; i < SHA_DIGEST_LENGTH; i++) sprintf(testHash+2*i, "%02x", binaryHash[i]); } else if (strcmp(type, "SHA256") == 0) { unsigned char binaryHash[SHA256_DIGEST_LENGTH]; unsigned char* sha256String = (unsigned char*)tempString; SHA256(sha256String, strlen(tempString), binaryHash); for (i = 0; i < SHA256_DIGEST_LENGTH; i++) sprintf(testHash+2*i, "%02x", binaryHash[i]); } // printf("Proc %d: %s\n", myRank, tempString); // Debugging info FILE* pFile; pFile = fopen (hashFile,"r"); if (pFile == NULL) { perror ("Error opening file, aborting\n"); MPI_Finalize(); exit(-3); } while (fscanf (pFile, "%s", str) != EOF) { foundPass = (strcmp(testHash, str) == 0); if (foundPass) { printf("%s, %s\n", tempString, testHash); } } fclose (pFile); }
void checkPass(char* hash, char* tempString) { char testHash[HASH_LENGTH]; int i; bool foundPass = false; sprintf(testHash, "%s", md5.digestString(tempString)); // printf("%s\n", tempString); for (i = 0; i < HASH_LENGTH; i++) {// Checks if the hashes match if (testHash[i] != hash[i]) { foundPass = false; break; } else { foundPass = true; } } if (foundPass) { printf("The password is %s\n", tempString); exit(0); } }