日記として機能するコンソール アプリケーションを開発中です。この段階で、私はログイン認証を開発していて、少し壁にぶつかっています! ログイン用と日記用の両方のストレージでテキスト ファイルを扱うので、これらのテキスト ファイルを暗号化して覗き見されないようにしたいと考えています。
さて、問題は、復号化 >> ユーザーの確認 && パス >> 再度暗号化する方法がわからないことです。
それはこれらの線に沿っているでしょうか?:
プログラムの負荷
passwords.txt を復号化する
プログラムが終了すると、encryptFile() が実行されます。
ユーザー入力の検証
passwords.txt を暗号化する
私が正しい方向に進んでいる場合、これを実装するにはどうすればよいですか? C++ を使用したテキスト ファイルの暗号化のチュートリアルを検索しましたが、あまり役に立ちませんでした。
これは、初心者用の password.txt コードです。私が見逃した暗号化のチュートリアル/記事があれば、投稿してください!
void checkPasswordFile() {
string username;
string password;
string passwordAgain;
string userIn;
string passIn;
string line;
ifstream passwordFile("passwords.txt");
istringstream instream;
if (passwordFile.good()) {
cout << "\t==================================" << endl;
cout << "\t----------------------------------" << endl;
cout << "\tYou are a returning user, please fill in your details" << endl;
while(!passwordFile.eof()) {
getline(passwordFile, line);
instream.clear();
instream.str(line);
username = line;
getline(passwordFile, line);
instream.clear();
instream.str(line);
password = line;
}
do {
cout << "Username: " << endl;
cin >> userIn;
cout << "Password: " << endl;
cin >> passIn;
if (userIn == username && passIn == password) {
displayMenu();
} else {
cout << "Username and Password Do Not Match, Try Again" << endl;
}
} while(userIn != username && passIn != password);
} else {
cout << "file no exist";
ofstream passwordFile;
passwordFile.open ("passwords.txt", ios:: in | ios::app);
cout << "\t==================================" << endl;
cout << "\t----------------------------------" << endl;
cout << "\tThis is your first run, please enter a username and password" << endl;
cout << "\tUsername: " << endl;
cin >> username;
cout << "\tPassword: " << endl;
cin >> password;
/*
Do Loop:
Prompts Re-Entry if PasswordAgain is not equal to Password
*/
do {
cout << "Re-Type Password: ";
cin >> passwordAgain;
if(password != passwordAgain) {
cout << "Passwords Do Not Match! Try Again" << endl;
}
} while(password != passwordAgain);
passwordFile << username << "\n";
passwordFile << password;
}
}
どうぞよろしくお願いいたします。
ps私の人生では、どうすればよいかわかりません:
Username:[cin>>username] 同じコンソール行で、重複して申し訳ありませんが、それ自体の投稿に十分な大きさの質問とは見なされませんでした! ありがとう。
編集:
ユーザー名を復号化して、テキスト ファイルを作成して保存することに成功しました。その後、ユーザーが戻ってくると、入力内容が暗号化されてファイルと比較されます。
これは短い単語に対してのみ機能する問題であり、ユーザーパスは機能しますが、ユーザー名とパスワードは機能しません...理由は何ですか? これが私の暗号化コードです:
char encryptKey = 'h';
cout << "\tUsername: ";
cin >> userIn;
cout << "\tPassword: ";
cin >> passIn;
for (int i = 0; i < userIn.size(); i++) {
userIn[i] ^= encryptKey;
}
for (int x = 0; x < passIn.size(); x++) {
passIn[x] ^= encryptKey;
}
if (userIn == username && passIn == password) {
displayMenu();
} else {
cout << "\tUsername and Password Do Not Match, Try Again" << endl;
}