Проверь на любом сайте.
С++
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
#include "lib.h"
int showMenu(){
int choise;
do{
cout << "1) Authorization." << endl;
cout << "2) Registration." << endl;
cout << "3) Exit." << endl;
cout << "Make your choise: ";
cin >> choise;
if(cin.fail()){
cin.clear();
cin.ignore();
system("cls");
cout << "Input is incorrect.\n";
}
}while(choise <1 || choise >3);
return choise;
void registerUser(){
cout << " Registration \n";
cout << "Type your login (30 symbols max): ";
char login[31] = {0};
cin >> login;
cout << "Type password: ";
char password[32] = {0};
cin >> password;
cout << "Confirmation: ";
char password2[32] = {0};
cin >> password2;
FILE *f = NULL;
fopen_s(&f, "base.txt", "at");
if(f){
fprintf_s(f,"%s;%s\n",login, password);
fclose(f);
} else {
cout << "Registration is fail. File is not created.\n";
bool checkUser(char* aLogin, char* aPassword){
fopen_s(&f, "base.txt", "rt");
while(!feof(f)){
char buff[100] = {0};
fgets(buff,99,f);
if(strlen(buff)){
buff[strlen(buff) - 1] = '\0';
char *login = buff;
char *password = strstr(buff,";") + 1;
*(password - 1) = '\0';
/*cout << "Login:" << login << endl;
cout << "Password:" << password << endl;*/
if(_stricmp(aLogin,login) == 0 &&
_stricmp(aPassword,password) == 0
)
return true;
cout << "Users file does not exists.\n";
return false;
Проверь на любом сайте.
С++
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
#include "lib.h"
int showMenu(){
int choise;
do{
cout << "1) Authorization." << endl;
cout << "2) Registration." << endl;
cout << "3) Exit." << endl;
cout << "Make your choise: ";
cin >> choise;
if(cin.fail()){
cin.clear();
cin.ignore();
system("cls");
cout << "Input is incorrect.\n";
}
}while(choise <1 || choise >3);
return choise;
}
void registerUser(){
system("cls");
cout << " Registration \n";
cout << "Type your login (30 symbols max): ";
char login[31] = {0};
cin >> login;
cout << "Type password: ";
char password[32] = {0};
cin >> password;
cout << "Confirmation: ";
char password2[32] = {0};
cin >> password2;
FILE *f = NULL;
fopen_s(&f, "base.txt", "at");
if(f){
fprintf_s(f,"%s;%s\n",login, password);
fclose(f);
} else {
cout << "Registration is fail. File is not created.\n";
}
}
bool checkUser(char* aLogin, char* aPassword){
FILE *f = NULL;
fopen_s(&f, "base.txt", "rt");
if(f){
while(!feof(f)){
char buff[100] = {0};
fgets(buff,99,f);
if(strlen(buff)){
buff[strlen(buff) - 1] = '\0';
char *login = buff;
char *password = strstr(buff,";") + 1;
*(password - 1) = '\0';
/*cout << "Login:" << login << endl;
cout << "Password:" << password << endl;*/
if(_stricmp(aLogin,login) == 0 &&
_stricmp(aPassword,password) == 0
)
return true;
}
}
fclose(f);
} else {
cout << "Users file does not exists.\n";
}
return false;
}