-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhile.cpp
81 lines (79 loc) · 4.19 KB
/
while.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
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
#include "variable.h"
int main()
{
while(true)
{
//CLI initialize
std::cout << "---------------------------------" << std::endl;
std::cout << " Options " << std::endl;
std::cout << "---------------------------------" << std::endl;
std::cout << "(1). Exit" << std::endl;
std::cout << "(2). Save the password " << std::endl; //save the password and it will write "log" for record password wrote
std::cout << "(3). Test unlock current password" << std::endl; //Test and it will to save "Success-log" and "Faild-log"
std::cout << "---------------------------------" << std::endl;
std::cout << "[Enter]: ";
//Enter select
std::cin >> option;
//start to judge
if(option == '1')
{
exit(1); //End the program
}
else if(option == '2')
{
system("cls"); // Windows API
std::cout << "[Enter the new password]: ";
std::cin >> str_password;
out.open(Log_file, std::ios::app);
out << "[ " << 1900 + ltm->tm_year << "/" << 1 + ltm->tm_mon << "/" << ltm->tm_mday << " " << ltm->tm_hour << ":" << ltm->tm_min << ":" << ltm->tm_sec << " ] " << "New password created: " << str_password << std::endl; //Wrote into pswd.log
out.close();
system("cls");
}
else if(option == '3')
{
system("cls");
std::cout << "[Enter the current password]: ";
std::cin >> check_str_password;
if(check_str_password == str_password)
{
std::cout << "Successed!" << std::endl;
out.open(Log_file, std::ios::app);
out << "[ " << 1900 + ltm->tm_year << "/" << 1 + ltm->tm_mon << "/" << ltm->tm_mday << " " << ltm->tm_hour << ":" << ltm->tm_min << ":" << ltm->tm_sec << " ] " << "Successed for Unlock by password: " << check_str_password << std::endl; //Wrote into pswd.log
out.close();
system("cls");
}
else
{
out.open(Log_file, std::ios::app);
out << "[ " << 1900 + ltm->tm_year << "/" << 1 + ltm->tm_mon << "/" << ltm->tm_mday << " " << ltm->tm_hour << ":" << ltm->tm_min << ":" << ltm->tm_sec << " ] " << "Failed for Unlock by password: " << check_str_password << std::endl; //Wrote into pswd.log
out.close();
while(true)
{
if(times_for_locked == 0){
exit(1);
}
if(times_for_locked == 1){
std::cout << "WARNING! THE LAST CHANCE FOR ENTER PASSWORD, IF ENTER WRONG PASSWORD AGAIN, THE PROGRAM WILL CLOSED!" << std::endl;
}
std::cout << "FAILED! WRONG PASSWORD!" << std::endl << "PLEASE ENTER IN AGAIN: ";
std::cin >> check_str_password;
system("cls");
if(check_str_password == check_str_password)
{
break;
}
times_for_locked = times_for_locked - 1; //reduse the times with 1
out.open(Log_file, std::ios::app);
out << "[ " << 1900 + ltm->tm_year << "/" << 1 + ltm->tm_mon << "/" << ltm->tm_mday << " " << ltm->tm_hour << ":" << ltm->tm_min << ":" << ltm->tm_sec << " ] " << "Failed for Unlock by password: " << check_str_password << std::endl; //Wrote into pswd.log
out.close();
}
std::cout << "Successed!" << std::endl;
out.open(Log_file, std::ios::app);
out << "[ " << 1900 + ltm->tm_year << "/" << 1 + ltm->tm_mon << "/" << ltm->tm_mday << " " << ltm->tm_hour << ":" << ltm->tm_min << ":" << ltm->tm_sec << " ] " << "Successed for Unlock by password: " << check_str_password << std::endl; //Wrote into pswd.log
out.close();
system("cls");
}
times_for_locked = 3; //regive the value
}
}
}