-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhello.cpp
More file actions
136 lines (116 loc) · 2.48 KB
/
hello.cpp
File metadata and controls
136 lines (116 loc) · 2.48 KB
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
#include <iostream>
#include <fstream>
#include <string>
// Functions declarations
void signup();
void login();
void search();
void forgor();
int main()
{
int n;
std::cout << "Welcome! \n1.Register(Enter 1)\n2.Login(Enter 2)\n3.Forgor(Enter 3)\n\n";
std::cin >> n;
switch (n)
{
case 1:
signup();
break;
case 2:
login();
break;
case 3:
forgor();
break;
default:
break;
}
}
void signup()
{
std::string ruserId, rpassword, rid, rpass;
system("cls");
std::cout << "\nEnter username: ";
std::cin >> ruserId;
std::cout << "\nEnter password: ";
std::cin >> rpassword;
std::ofstream f1("records.txt", std::ios::app);
f1 << ruserId << ' ' << rpassword << std::endl;
system("cls");
std::cout << "\n You have registered succefully !\n";
main();
}
void login()
{
int count = 0;
std::string userId, password, id, pass;
system("cls");
std::cout << "\nEnter username: ";
std::cin >> userId;
std::cout << "\nEnter password: ";
std::cin >> password;
std::ifstream input("records.txt");
while (input >> id >> pass)
{
if (id == userId && pass == password)
{
count++;
system("cls");
}
input.close();
if (count == 1)
{
std::cout << userId << "\n\tYou have succesfully logged in !\n\n";
}
else
{
std::cout << "\nError! \nCheck credentials\n";
main();
}
}
}
void search()
{
int count = 0;
std::string suserId, sId, spass;
std::cout << "Enter username you remember";
std::cin >> suserId;
std::ifstream f2("records.txt");
while (f2 >> sId >> spass)
{
if (sId == suserId)
{
count++;
}
}
f2.close();
if (count == 1)
{
std::cout << "Account found! \nYour password is " << spass<<"\n";
main();
}
else
{
std::cout << "Sorry, can't find your username!";
main();
}
}
void forgor()
{
int option;
system("cls");
std::cout << "\nTo recover credentials, follow through\n";
std::cout << "Enter 1 to search by username in records\nEnter 2 to return to main menu\n";
std::cin >> option;
switch (option)
{
case 1:
search();
break;
case 2:
main();
default:
std::cout << "\n Wrong choice ! Reenter choice";
forgor();
}
}