Merging FSTREAM & Files with .exe's

closed account (1vD3vCM9)
hey, i got a question
yesterday i learned fstream, i made an login & password system with files.
here is my code for :
filesystemregister.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#pragma once
#include <iostream>
#include <Windows.h>
#include <string>
#include <tchar.h>
#include <fstream>
#include "System.h"

using namespace std;

void filesystem::filesystemregister()
{
	bool registered = false;
	string registeredistrue = "Registered = true";
	char confirm;
	string newusername;
	string newpassword;
	string choice;
	ofstream writedata("data.conf", ios::out | ios::app | ios::binary);
	ifstream readdata("data.conf"); // ifstream = read from file
	cout << "Hi, Welcome to oren's program project!\n\n";
	cout << "This project is Very new.\n\n";
	cout << "type: 'register' to register a new account ( you can do it ONLY THREE TIMES! )\n";
	cout << "If you are already registered, type: 'continue'\n";
	cout << "C>";
	cin >> choice;
	if (choice == "register")
	{
		system("CLS");
		cout << "Username: ";
		cin >> newusername;
		cout << "\n";
		cout << "Password: ";
		cin >> newpassword;
		cout << "\n\n\n";
		cout << "------YOUR_INFORMATION------\n\n";
		cout << "Username: " << newusername << endl;
		cout << "Password: " << newpassword << endl;
		cout << "Confirm? Y/N\n\n";
		cin >> confirm;
		if (confirm = 'L' || 'l')
		{
			registered = true;
			cout << "Writing Data...\n";
			system("PAUSE");
			if (writedata.is_open() && readdata.is_open())
			{
				registered = true;
				if (registered = true)
				{
					writedata << registeredistrue << endl;
				}
				writedata << newusername << endl;
				writedata << newpassword << endl;
				startloginsystem();
				writedata.close();
				readdata.close();
			}
			if (writedata.fail())
			{
				cerr << "Error Reading/Finding file! Try Reinstalling the program!\n";
			}
		}
		else if (confirm = 'N' || 'n')
		{
			system("PAUSE");
			system("CLS");
			filesystem();
		}
		else
		{
			cout << "You know what, i give up.\n";
		}
	}
	else if (choice == "continue" || "'continue'")
	{
		system("CLS");
		startloginsystem();
	}
	else
	{
		cout << "The Choice you entered does not exist.\n";
		system("PAUSE");
		system("CLS");
		filesystem();
	}
}


i got 2 questions.
1. can you help me improve this code?, i may need some help with it.
2. how do i merge files with .exe's? i mean, you know the game called powder toy?, it got FILES inside of the .exe, how can i do that?
because my whole system is working on reading files from the file, so if the person changes some info, he can change some details easily.

Thanks for answering.
I presume you are working only on Windows (because you are using .exe files).

You can store data (such as a text file) in an executable as a resource.
http://www.google.com/search?btnI=1&q=msdn+Finding+and+Loading+Resources
http://www.google.com/search?btnI=1&q=msdn+Resource+Functions

You also have to know how to create and compile resources into your .exe:
http://www.google.com/search?btnI=1&q=msdn+Resource+Compiler


There is a hitch, though: You cannot modify an .exe file that is currently executing.

Programs that do this (like updaters) do it by having another small .exe whose sole purpose is to modify the main .exe. The main .exe will start the small .exe and terminate, at which point the small .exe will modify the main .exe, then restart the main .exe. This is a lot of grief.

A better bet is just to store your data in a file that the user is unlikely to find by accident -- put it in the user's local application data. Find this directory with the ShGetKnownFolderPath() WinAPI function.
http://www.google.com/search?btnI=1&q=msdn+SHGetKnownFolderPath
Use the FOLDERID_LocalAppData value as the first argument.
The pathname of files for your application should be named something like
    LocalAppDataPath \ YourExe'sName \ data.conf 
(And don't forget to #include <shlobj.h> and link with shell32.dll.)


One major suggestion for improvement: load the file into memory, modify the memory, and overwrite the file. It is simple enough to have structs with username/salt/password-hash data in a deque.

BTW, if you are serious about actual password data, there is a lot to learn. Here is some good reading to get started:
https://crackstation.net/hashing-security.htm

Good luck!
Topic archived. No new replies allowed.