I am trying to find the plain text password of a hashed password that is in the text file. I have done the code and everything, but when I input my hash it just prints it the same hash.
Here is the code that produces the hash:
//To Compile: g++ -o our_crypt our_crypt.cpp -lcrypt
#include <iostream>
#include <unistd.h>
using namespace std;
int main()
{
string plain_pass="password";
string salt="salt";
cout << "Please enter a plaintext password:\n";
cin >> plain_pass;
cout <<"\nNow enter a salt: \n";
cin >> salt;
const char * arg1 = plain_pass.c_str();
const char * arg2 = salt.c_str();
string hash = crypt(arg1, arg2);
cout << "The Hash is: " << hash <<"\n";
return 0;
}
Here is my code that should retrieve the hashed password in from a text file:
#include <iostream>
#include <cstdlib>
#include <stdio.h>
#include <fstream>
#include <cstring>
#include <string>
#include <iostream>
#include <string>
int main()
{
// :: is called the Scope Resolution Operator. It makes it clear to which namespace or class a symbol belongs.
std::cout << "Enter the hash to break:\n";
std::string passHash;
std::cin >> passHash;
std::string fileName;
std::cout<< "Enter in file: \n";
std::cin >> fileName;
std::fstream inFile;
inFile.open(fileName,std::ios::in);
if (inFile.is_open())
{ //checking whether the file is open
std::string nline;
while(getline(inFile, nline))
{ //read data from file object and put it into string.
if(nline == passHash)
{
break;
}
}
std::cout <<"The password is: \n" <<passHash <<"=" <<nline;
}
inFile.close();
return 0;
}
Here is the output from my terminal:
Enter the hash to break:
1vpZi631NyGhI
Enter in FIle:
words.txt
The password is:
1vpZi631NyGhI=
As you can see, it should display the password which is "tree" and not the hash.
I am asking for assistance for educational purposes, and not giving me the answer.