create a password

how can we create a password and change the password?
thank you!!
http://cplusplus.com/forum/beginner/1/
We need more information on your programming problem to help.
Try this if you get any bugs tell me
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
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
	int Choice = 0;                                       //User Choices
	ifstream Reader;                                    //Reads Password.txt
	ofstream Writer;                                     //Writes in Password.txt
	string UserPassword , PasswordCheck , NewPassword; //Strings for passwords 
	Reader.open ("C:\\Password.txt");        //Opens Password.txt
	if (Reader.is_open ())
	{
		getline (Reader , UserPassword);         //Reads from Password.txt
		cout << "Please enter your exsiting password." << endl;
		getline (cin , PasswordCheck);                             
		cin.sync ();
		if (PasswordCheck == UserPassword)    //Checks PasswordCheck 
		{
			cout << "Do you wish to change the password (1 = Yes 2 = No)" << endl;
			cin >> Choice;
			cin.sync ();
			if (Choice == 1)
			{
				cout << "Please enter the new password." << endl;
				getline (cin , NewPassword);
				cin.sync ();
				Writer.open ("C:\\Password.txt");
				Writer << NewPassword << endl;
				Writer.close ();
				cout << "Please restart the program." << endl;
			}
			else
			{
				cout << "Hello World!" << endl;        //Displays Hello World!
			}
			Reader.close ();
		}
		else
		{
			cout << "Incorrect password." << endl;
		}
	}
	else            
	{
		cout << "Please enter your new password." << endl;  //Asks for new password
		getline (cin , UserPassword);
		cin.sync ();
		Writer.open ("C:\\Password.txt");
		Writer << UserPassword << endl;
		Writer.close ();
		cout << "Please restart the program." << endl;
	}
	cout << "Press ENTER to end the program." << endl;
	cin.get ();
	return 0;
}

That should give you this

//First Run
Please enter your new password.
Hello World
Please restart the program.
Press ENTER to end the program.

//Second Run
Please enter your exsiting password.
Hello World
Do you wish to change the password (1 = Yes 2 = No)
1
Please enter the new password.
Weezer
Please restart the program.
Press ENTER to end the program.

//Third Run
Please enter your exsiting password.
Weezer
Do you wish to change the password (1 = Yes 2 = No)
2
Hello World!
Press ENTER to end the program.
Last edited on
Topic archived. No new replies allowed.