Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Character.h"
- #include <iostream>
- #include <fstream>
- void Character::CreatePlayer (std::string pname, std::string ppass)
- {
- std::ofstream WriteFile;
- WriteFile.open(pname + ".txt");
- WriteFile << pname << ";" << ppass;
- WriteFile.close();
- std::cout << "Your account has been created. (Name: " << pname << " || Password: " << ppass << ")" << std::endl;
- name.push_back(pname);
- pass = ppass;
- }
- void Character::LoadPlayer (std::string pname, std::string ppass)
- {
- std::ifstream ReadFile;
- std::string filename;
- std::string filepass;
- ReadFile.open(pname + ".txt");
- while (!ReadFile.eof())
- {
- getline(ReadFile, filename, ';');
- getline(ReadFile, filepass, ';');
- if (!ppass.compare(filepass))
- {
- std::cout << "You have logged in successfully." << std::endl;
- name.push_back(filename); // I will make this search whether that name exists in vector first, then push back if it doesn't.
- pass = filepass;
- break;
- }
- else
- {
- std::cout << "You have entered an invalid password." << std::endl;
- }
- }
- ReadFile.close();
- }
- bool Character::CheckPlayer (std::string pname)
- {
- std::ifstream ReadFile;
- ReadFile.open(pname + ".txt");
- if (ReadFile.is_open())
- {
- return true;
- ReadFile.close();
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment