Help with login system.

Hi i posted earlier with a login system and now i've improved it but there is still some errors. I wrote this code in my friend's laptop with visual studio 2010. it works but when i register a new user the program needs to be restarted before the program recognizes the new user and password, but when it comes to old user and passwords stored in the txt file it'll work just fine. My other problem is that when i transferred the code to my laptop with devc++ it won't accept even the old user and passwords. I can't download visual studio from dreamspark because the secure download manager won't let me(it says something about active scripting even tho i have it on). Help will be appreciated.

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
88
89
90
91
92
93
  #include<iostream>
#include<string>
#include<fstream>

using namespace std;
ofstream user;
ofstream pass;
char reg();
char login();
int main()
{
	char y = 'y';
	while (y == 'y'){
		char choice;
		cout << "Do you have an account(y/n): ";
		cin >> choice;
		if (choice == 'y'){
			if (login() == 'y'){
				cout << "Login Successful" << endl;
				system("pause");
			}
			else{
				
				cout << "Login Failed!" << endl;
				cout << "Would you like to try again? (y/n) ";
				cin >> y;
				}
			}
		else{
			y = reg();
		}
			}
	return 0;
	}
char reg(){
	/*ofstream user;
	ofstream pass;*/
	user.open("user.txt", ios_base::app);
	pass.open("pass.txt", ios_base::app);
	string username, password;
	cout << "Enter desired username: ";
	cin >> username;
	cout << "\nEnter desired password: ";
	cin >> password;
	user << username << "\n";
	pass << password << "\n";
	system("cls");
		cout << "Thank you";
		system("pause");
		system("cls");
       // user.close();
       // pass.close();

		
		return 'y';
	/*user.open("user.txt", ios_base::app);
	pass.open("pass.txt", ios_base::app);
	string user, pass;
	cout << "Enter your user name: ";
	cin>>user;
	cout << "\n Enter yo paswood: ";
	cin >> pass;
	user << user << "~";
	pass << pass << "~";*/
}
char login(){
	system("cls");
	ifstream user;
	ifstream pass;
	string username, password;
	string u[1000], p[1000];
	int i;
	cout << "Please enter your username: ";
	cin >> username;
	cout << "Please enter your password: ";
	cin >> password;
	user.open("user.txt", ios_base::app);
	pass.open("pass.txt", ios_base::app);
	//replace with !=eof later
	for (i = 0; i < 1000; i++){
		getline(user, u[i]);
	}
	for (i = 0; i < 1000; i++){
		getline(pass, p[i]);
	}
	for (i = 0; i < 1000; i++){
		if (username == u[i] && password == p[i])
			return 'y';
	}
	return 'n';
	
}
Topic archived. No new replies allowed.