/* Put this in the same directory as sha-256.h and sha-256.c * Build with this command: g++ login_system.cpp sha-256.c * If you have an error about "invalid conversion..." on line 139, change * line 139 to this: * const uint8_t *p = (const uint8_t*)data; * C++ requires an explicit cast here, but C does not. */ #include "sha-256.h" #include #include using namespace std; const char *pwdhash = "4ea511963388132dd56b3b23fdfa1a25b952a8fe958afc7938622a33156bebf3"; void hash_to_string(char string[65], const uint8_t hash[32]){ for (uint8_t i = 0; i < 32; i++) { string += sprintf(string, "%02x", hash[i]); } } void win(){ cout << "You got the password right!\n"; } int main(){ string password; cout << "Enter the password: "; cin >> password; uint8_t hash[32]; calc_sha_256(hash, password.c_str(), password.length()); char hash_string[65]; hash_to_string(hash_string, hash); if(strcmp(hash_string, pwdhash)){ cout << "Sorry, you don't seem to know the password!" << endl; return 1; } win(); return 0; }