Advertisement
Guest User

Untitled

a guest
Mar 8th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. // testApp.cpp : Defines the entry point for the console application.
  2. //justsomeRandomUser|ffee6cff9bffc173ffa732ff8cffcfffdfffc8ffde0bffde1e31ff88ff91|SPECIAL|ADMIN
  3. #include "openssl\des.h"
  4.  
  5. #include <stdio.h>
  6. #include <Windows.h>
  7. #include <string>
  8. #include <iostream>
  9. #include "stdafx.h"
  10. #include "windows.h"
  11. #include <string>
  12. #include <iostream>
  13. #include <algorithm>
  14. #include <stdexcept>
  15. #include <iomanip>
  16. #include <sstream>
  17. #include <openssl/evp.h>
  18. #include <openssl/pem.h>
  19. #include <openssl/aes.h>
  20. #include <openssl/err.h>
  21. #include <stdio.h>
  22. #include <string>
  23. #include <string.h>
  24. #include "ServerCrypto.h"
  25. #include <exception>
  26.  
  27. using namespace std;
  28.  
  29. void to_hex(char* inut,char* output,int size )
  30. {
  31. std::stringstream s;
  32. s.fill('0');
  33. for ( size_t i = 0 ; i < size ; ++i )
  34. s << std::setw(2) << std::hex << (unsigned short)inut [i];
  35.  
  36. strcpy(output,s.str().c_str());
  37.  
  38. }
  39.  
  40.  
  41. bool login( char* username,char* password)
  42. {
  43. try
  44. {
  45.  
  46. unsigned char* encryptionKey=(unsigned char*)"gertrud";
  47. static ServerCrypto sc;
  48.  
  49. int encMsgLen=0;
  50.  
  51. if((encMsgLen = sc.aesEncrypt(username, &encryptionKey)) == -1)
  52. {
  53. return false;
  54. }
  55.  
  56. int encryptedUsernameLength=(strlen((const char*)encryptionKey)*2)+1;
  57.  
  58. char* encryptedUsernameAsHex=new char[encryptedUsernameLength]();
  59.  
  60. to_hex((char*)encryptionKey,encryptedUsernameAsHex,encMsgLen);
  61.  
  62. if(!strcmp(encryptedUsernameAsHex ,password))
  63. {
  64. return false;
  65. }
  66. else
  67. {
  68. char errorMessage[512];
  69. sprintf(errorMessage,"Login failed for %s using password %s",username,password);
  70. printf("%s",errorMessage);
  71. }
  72. }
  73. catch(exception& e)
  74. {
  75. printf("%s", e.what());
  76. }
  77. }
  78.  
  79. char* ReadFile(char *filename)
  80. {
  81. char *buffer = NULL;
  82. int string_size,read_size;
  83. FILE *handler = fopen(filename,"rb");
  84.  
  85. if (handler)
  86. {
  87. //seek the last byte of the file
  88. fseek(handler,0,SEEK_END);
  89. //offset from the first to the last byte, or in other words, filesize
  90. string_size = ftell (handler);
  91. //go back to the start of the file
  92. rewind(handler);
  93.  
  94. //allocate a string that can hold it all
  95. buffer = new char[string_size +1 ]() ;
  96. //read it all in one operation
  97. read_size = fread(buffer,sizeof(char),string_size,handler);
  98. //fread doesnt set it so put a \0 in the last position
  99. //and buffer is now officialy a string
  100.  
  101.  
  102. if (string_size != read_size) {
  103. //something went wrong, throw away the memory and set
  104. //the buffer to NULL
  105. delete[] buffer;
  106. buffer = NULL;
  107. }
  108. }
  109.  
  110. return buffer;
  111. }
  112.  
  113.  
  114. int main(int argc, char* argv[])
  115. {
  116.  
  117. char* input=ReadFile("C:\\input.bin");
  118.  
  119. char* username = strtok (input,"|");
  120. char* password = strtok (NULL,"|");
  121.  
  122. if( login(username,password))
  123. {
  124. printf("Welcome %s",username);
  125. }
  126.  
  127. delete[] input;
  128.  
  129. return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement