user data security

Pages: 12
@Thomas, sorry your given code is not working i mean, content of the text file is not displayed

It worked on my computer and displayed the file correctly.
Are you sure that the filename is correct and the file contains text?
Could you post some content of the file?
@MikeyBoy, even if I'm putting the input in line, content is not being displayed

Without seeing the code you're actually talking about, we can't possibly know what's wrong.

You're really not making this easy for us to help you.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
char line[1000];
					cout<<"\t\tEnter File name: ";
					cin>>fname;
					ifstream myfile(fname);

					while (!myfile.eof())
					{
					myfile >> line;
					cout << line << '\n';



					myfile.close();

					}


yes Thomas, the file I'm trying to open is test which contains the following code as content
test.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
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
void main()
{
char user[]="mini";
char pass[]="qwert";
char username[10], password[10];
int i;

cout << "username";
cin >> username;

cout << "password";
cin >> password;

if(strcmp(username,user) && strcmp(password,pass))
{
cout << "correct login. enter i";
cin >> i;
}

else
{
cout << "kuwcyvku";
cin >> i;
}
}



the program is not showing any error but this content is not getting displayed, tough it is working well in Dev C++ as i told but i have to implement it in Turbo C++
and string is not considered as any data type in Turbo C++, so I replaced string with char array,
and string is not considered as any data type in Turbo C++, so I replaced string with char array,


did you include <string> ?
It would be very odd if you could use cout, cin and istream but not string.

Anyway it should work with chars as well.

Try this code. Maybe it will show at least some info.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
ifstream myfile(fname);
  if (!myfile)
  {
    cerr << "Error opening file: " << fname << endl;
    return;
  }
  myfile.seekg(0, ios_base::end);
  streamoff filelen = myfile.tellg();
  myfile.seekg(0, ios_base::beg);
  cout << "Length of " << fname << " = " << filelen << endl;
  while (!myfile.eof())
  {
    myfile.getline(line, sizeof(line));
    cout << line << endl;
  }
  myfile.close();


not showing anything

i copied your module and pasted it, still no changes in the output....nothing is being displayed on the output screen
If the code is reached there must be an output, either the error message or the message with the file len.
Maybe there is an error before so that the code is not reached.
Have you ever used a debugger debugger?
Can you post the complete code again?
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#include <iostream.h>
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <fstream.h>




void lockfolder();

int main()
{


	int i,a=0,count=0;
	char c,fname[10];
	char user[12] = "miniproject";
	char pass[11] = "qwert!@#$%";
	unsigned int choice=0, lock, yes;
	cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";

	char username[11], password[10];
	cout << "\n\t\t\tWelcome to our Security System..!!!" << endl;

	while(count<3)

	{

	cout << "\n\t\tUsername :: ";
	cin >> username;

	cout << "\n\t\tPassword :: ";
	cin >> password;

	if(strlen(username) < 11)
		{
			cout << "\n\t\tincorrect id password";
			count++;
		}

	if(strlen(password) < 10)
		{
			cout << "\n\t\tincorrect id password";
			count++;
		}

	if(strcmp(username, user)==0 && strcmp(password, pass)==0)
		{



				cout << "\n\n\t\t\t\t Login Successful" << endl;
				cout << "\t\t\t\t-------------------\n\n" << endl;
				cout << "\n\n\t\t\t  --=Welcome to the software=--" << endl;
				cout << "\t\t\t=================================\n\n\n" << endl;
				count=3;


				do
				{


				switch(a)

				{


			case 0:
			{


			cout << "\t\tAvailable commands:\n";
			cout << "\t\t-------------------\n\n";
			cout << "\t\t0. list commands\n";
			cout << "\t\t1. write a new file\n";
			cout << "\t\t2. load a file\n";
			cout << "\t\t3. exit program\n";

			break;

			}



				case 1:
				{

					ofstream out;
			cout<<"\t\tEnter File name:";
			cin>>fname;
			out.open(fname);

					cout<<"\t\tEnter contents to store in file (Enter # at end):\n";
			while((c=getchar())!='#')
			{

			    out<<c;

					}
					cout<<"Is it a confidential file? \n Want to encrypt the content for security? \n press 1 else press 2 :: ";
					cin>>choice;

					if(choice==1)
					{

					encrypt();

					}

					else
					{

						cout<<"quitting...";

					}


			out.close();
			break;

				}

				case 2:
				{
					/*cout<<"enter file name to open ";
					cin>>fname;
					if(lock==1)
					{

					cout<<"sorry..this file is locked.\n Want to unlock? press 1 ";
					cin>>yes;

					if(yes==1)
					{

					cout<<"enter unlock code ";
					cin>>code;

					if(code==mycode[12])
					{

					lock=0;

					}
					else

					cout<<"wrong code";

					return 0;

					}
					else

					return 0;
					} */

					char line[1000];
					cout<<"\t\tEnter File name: ";
					cin>>fname;

					fflush(stdin);
       					ifstream myfile;
       					myfile.open("fname",ios::in);
       					while(myfile.eof()==0)
       					{
						myfile.getline(line,100);
						cout<<line;
      	 				}


				  break;
				}

				case 3:
				{

				 cout<< "\n\n\t\tTHANK YOU FOR USING THIS SOFTWARE...";

				  break;
				}


				default:

					cout << "\n\n\t\tUnrecognized command. Enter '0' to view command list\n";


			}


			cout << "\n\t\tEnter command:";
		cin >> a;

	}

	while (a!=3);
		}


			else
			{

				cout << "\n\t\tInvalid login details. Please try again"
				<< endl;
				count++;

			}

		}
	 return 0;
	}











here it is
the code for load file i have used here is not working tough the same code is working in my encrypt file program, however in place of fname i have given the name of file as input in encryption program
it's done..!!!
:)
Topic archived. No new replies allowed.
Pages: 12