Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <dirent.h>
  5. #include <string>
  6. #include <string.h>
  7.  
  8. std::vector<std::string> split(std::string str, char delim) {
  9.     std::vector<std::string> st;
  10.     std::string temp = "";
  11.     for (int pos = 0; pos < str.size(); pos++) {
  12.         if (str[pos] != delim)
  13.             temp += str[pos];
  14.         else {
  15.             st.push_back(temp);
  16.             temp = "";
  17.         }
  18.     }
  19.     if (temp.size()!=0)
  20.         st.push_back(temp);
  21.     temp = "";
  22.     return st;
  23. }
  24.  
  25. bool contains(std::string s1, std::string s2){
  26.     return strstr(s1.c_str(),s2.c_str());
  27. }
  28.  
  29. std::vector<std::string> getfiles(std::string ext) {
  30.     std::vector<std::string> output;
  31.     std::string path = ".";
  32.     DIR *dir;
  33.     struct dirent *ent;
  34.     dir = opendir(".");
  35.     while ((ent = readdir(dir)) != NULL) {
  36.         std::string name = ent->d_name;
  37.         if (strstr(name.c_str(),ext.c_str()))
  38.             output.push_back(name);
  39.     }
  40.     closedir(dir);
  41.     return output;
  42. }
  43.  
  44. int main(int argc, char** argv) {
  45.     int counter = 0;
  46.     std::vector<std::string> files = getfiles(".txt");
  47.     std::string line;
  48.     std::ofstream fs2("test.sql", std::ios_base::app);
  49.     std::vector<std::string> theme;
  50.     std::string login;
  51.     std::string password;
  52.     for (int s = 0; s<files.size();s++) {
  53.         std::ifstream fs(files[s].c_str());
  54.         while (getline(fs,line)) {
  55.             theme = split(line, ':');
  56.             if (theme.size()==1)
  57.                 continue;
  58.             login = theme[0];
  59.             password = theme[1];
  60.             if (contains(login, "'") || contains(password, "'"))
  61.                 continue;
  62.             fs2 << "INSERT INTO `users` (`login`,`password`,`ip`) VALUES ('" << login << "', '" << password << "', '');\n";
  63.             std::cout << "Written: " << counter << "\r";
  64.             counter++;
  65.         }
  66.         fs.close();
  67.     }
  68.     fs2.close();
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement