Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // testApp.cpp : Defines the entry point for the console application.
- //justsomeRandomUser|ffee6cff9bffc173ffa732ff8cffcfffdfffc8ffde0bffde1e31ff88ff91|SPECIAL|ADMIN
- #include "openssl\des.h"
- #include <stdio.h>
- #include <Windows.h>
- #include <string>
- #include <iostream>
- #include "stdafx.h"
- #include "windows.h"
- #include <string>
- #include <iostream>
- #include <algorithm>
- #include <stdexcept>
- #include <iomanip>
- #include <sstream>
- #include <openssl/evp.h>
- #include <openssl/pem.h>
- #include <openssl/aes.h>
- #include <openssl/err.h>
- #include <stdio.h>
- #include <string>
- #include <string.h>
- #include "ServerCrypto.h"
- #include <exception>
- using namespace std;
- void to_hex(char* inut,char* output,int size )
- {
- std::stringstream s;
- s.fill('0');
- for ( size_t i = 0 ; i < size ; ++i )
- s << std::setw(2) << std::hex << (unsigned short)inut [i];
- strcpy(output,s.str().c_str());
- }
- bool login( char* username,char* password)
- {
- try
- {
- unsigned char* encryptionKey=(unsigned char*)"gertrud";
- static ServerCrypto sc;
- int encMsgLen=0;
- if((encMsgLen = sc.aesEncrypt(username, &encryptionKey)) == -1)
- {
- return false;
- }
- int encryptedUsernameLength=(strlen((const char*)encryptionKey)*2)+1;
- char* encryptedUsernameAsHex=new char[encryptedUsernameLength]();
- to_hex((char*)encryptionKey,encryptedUsernameAsHex,encMsgLen);
- if(!strcmp(encryptedUsernameAsHex ,password))
- {
- return false;
- }
- else
- {
- char errorMessage[512];
- sprintf(errorMessage,"Login failed for %s using password %s",username,password);
- printf("%s",errorMessage);
- }
- }
- catch(exception& e)
- {
- printf("%s", e.what());
- }
- }
- char* ReadFile(char *filename)
- {
- char *buffer = NULL;
- int string_size,read_size;
- FILE *handler = fopen(filename,"rb");
- if (handler)
- {
- //seek the last byte of the file
- fseek(handler,0,SEEK_END);
- //offset from the first to the last byte, or in other words, filesize
- string_size = ftell (handler);
- //go back to the start of the file
- rewind(handler);
- //allocate a string that can hold it all
- buffer = new char[string_size +1 ]() ;
- //read it all in one operation
- read_size = fread(buffer,sizeof(char),string_size,handler);
- //fread doesnt set it so put a \0 in the last position
- //and buffer is now officialy a string
- if (string_size != read_size) {
- //something went wrong, throw away the memory and set
- //the buffer to NULL
- delete[] buffer;
- buffer = NULL;
- }
- }
- return buffer;
- }
- int main(int argc, char* argv[])
- {
- char* input=ReadFile("C:\\input.bin");
- char* username = strtok (input,"|");
- char* password = strtok (NULL,"|");
- if( login(username,password))
- {
- printf("Welcome %s",username);
- }
- delete[] input;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement