2016-11-09 8 views
0

サーバ/ウェブページ上でEXE(C++)を実行してEXEを応答させることはできますか、このEXE(C++)をJavaScript?htmlで実行するか、JavaScriptに変換する

コードをjavascriptに変換する必要がある場合はどうすればよいですか?私はjavascriptの基礎を知っているが、私は.txtファイルを読み書きする方法を知らない。

私のコードは基本的に私のウェブサイトに使用したいログインシステムですので、mysqlやデータベースを使う必要はありません。私はこれが遅く、おそらくそれをやっているばかげた方法だと知っていますが、それはプロジェクトのためです。どんな助けもありがとう!

EDIT:ログインボタンを押すと、上記のようにEXEファイルが表示されます。その後、ログインが成功した場合はEXEファイルがサーバーに返され、情報が返されます。 EXEファイルはサーバー上にある必要があるため、クライアントはダウンロードする必要はありません。

コード:

#include <iostream> 
#include <string> 
#include <fstream> 
#include <time.h> 

using namespace std; 
void cls() { system("cls"); } 

bool mainPage(string &username, string &password) { 
    cls(); 
    cout << "Username: "; getline(cin, username); 
    cout << "Password: "; getline(cin, password); 
    if(username != "" && password != "") { 
     return true; 
    } 
    else { 
     return false; 
    } 
} 

bool checkLogin(string &username, string &password, string &email, string &firstName, string &lastName) { 
    string pw = ""; 

    ifstream ifile(username + ".txt"); 
    if(ifile.is_open()) { 
     ifile >> pw >> email >> firstName >> lastName; 
     if(pw == password) { 
      return true; 
     } 
     else { 
      return false; 
     } 
    } 
    else { 
     return false; 
    } 
} 

bool loginFail() { 
    string fail = ""; 
    string undef = ""; 

    cls(); 
    cout << "'reg'" << endl; 
    cout << "'main'" << endl; 
    getline(cin, fail); 
    if(fail == "reg") { 
     return true; 
    } 
    else if(fail == "main") { 
     return false; 
    } 
    else { 
     cout << "\nCould not understand you." << endl; 
     getline(cin, undef); 
     return loginFail(); 
    } 
} 

bool regist() { 
    string un; 
    string pw; 
    string em; 
    string fn; 
    string ln; 
    string undef = ""; 

    cls(); 
    cout << "'main'" << endl; 
    cout << "\nNew username: "; getline(cin, un); 
    cout << "New password: "; getline(cin, pw); 
    if((un != "" && pw != "") && (un != "main" && pw != "main")) { 
     ifstream ifile(un + ".txt"); 
     if (ifile.is_open()) { 
      cout << "\nThis username is already taken." << endl; 
      getline(cin, undef); 
      return regist(); 
     } 
     else { 
      cout << "\nEmail: "; getline(cin, em); 
      cout << "\nFirst name: "; getline(cin, fn); 
      cout << "Last name: "; getline(cin, ln); 
      if(em != "" && fn != "" && ln != "") { 
       ofstream ofile; 
       ofile.open(un + ".txt"); 
       if (ofile.is_open()) { 
        ofile << pw << endl; 
        ofile << em << endl; 
        ofile << fn << endl; 
        ofile << ln << endl; 
        ofile.close(); 
        cout << "\nFile was successfully written to." << endl; 
        getline(cin, undef); 
        return true; 
       } 
       else { 
        cout << "\nFile could not open." << endl; 
        getline(cin, undef); 
        return regist(); 
       } 
      } 
      else { 
       cout << "\nYou didn't enter one of the above." << endl; 
       getline(cin, undef); 
       return regist(); 
      } 
     } 
    } 
    else if(un == "main" || pw == "main") { 
     return false; 
    } 
    else { 
     cout << "\nYou didn't do it correct." << endl; 
     getline(cin, undef); 
     return regist(); 
    } 
} 

void loginSuccess(string username, string password, string email, string firstName, string lastName) { 
    string undef = ""; 

    cls(); 
    cout << "You have successfully logged in." << endl; 
    cout << "\nUsername: " << username << endl; 
    cout << "Password: " << password << endl; 
    cout << "\nEmail: " << email << endl; 
    cout << "\nFrist name: " << firstName << endl; 
    cout << "Last name: " << lastName << endl; 
    getline(cin, undef); 
} 

int main(void) { 
    system("color a"); 
    string username = ""; 
    string password = ""; 
    string email = ""; 
    string firstName = ""; 
    string lastName = ""; 

    if(!mainPage(username, password)) { 
     return main(); 
    } 
    else { 
     if(!checkLogin(username, password, email, firstName, lastName)) { 
      if(!loginFail()) { 
       return main(); 
      } 
      else { 
       if (!regist()) { 
        return main(); 
       } 
       else { 
        return main(); 
       } 
      } 
     } 
     else { 
      loginSuccess(username, password, email, firstName, lastName); 
     } 
    } 
} 
+1

Google "CGI C++"スターターページ:https://www.tutorialspoint.com/cplusplus/cpp_web_programming.htm –

+0

しかし、私はこれを好きです。ログインボタンを押すと、上記のようにEXEファイルが表示されます。その後、ログインが成功した場合はEXEファイルがサーバーに返され、情報が返されます。 EXEファイルはサーバー上にある必要があるため、クライアントはダウンロードする必要はありません。 –

+0

CGIプログラムはサーバー側で実行されます。 C++プログラムはCGIプログラムにすることができます。リンク先ページの1番目の例を参照してください。 –

答えて

0

あなたは、ブラウザでJavaScriptからファイルシステムに書き込むことはできません。私はあなたがクライアント - サーバーのアーキテクチャを使用してアプリケーションを行う必要があると思います。たとえば、クライアントはユーザー名とパスワードの入力がある単純なHTMLページになり、サーバーはユーザーの資格情報を保存して確認します。この場合、Javascriptを使用してページからサーバーにデータを送信することができます。

+1

しかし、これはmysqlデータベースを必要とします。なぜなら、登​​録したアカウントを覚えておきたいからです。だから私はサーバーを閉じても、それはまだ作成されたアカウントを持っています。 –

関連する問題