diff --git a/Log/pswd.log b/Log/pswd.log new file mode 100644 index 0000000..69117af --- /dev/null +++ b/Log/pswd.log @@ -0,0 +1,5 @@ + +[ 2024/12/16 3:29:37 ] Failed for Unlock by password: j +[ 2024/12/16 3:29:37 ] Successed for Unlock by password: j +[ 2024/12/16 3:31:8 ] Failed for Unlock by password: 2 +[ 2024/12/16 3:31:8 ] Successed for Unlock by password: 3 diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..ac78836 --- /dev/null +++ b/main.cpp @@ -0,0 +1,29 @@ +#include "variable.h" //The customize function by self, so used "" for customize-function + +int main() +{ + if(!std::filesystem::exists(Log_Directory)) + { + //std::filesystem::create_directories(Log_Directory); // create the directory + if(std::filesystem::create_directories(Log_Directory)) + { + //std::cout << "Created!"; + } + else + { + std::cerr << "FILE WAS FAILD TO CREAT, PLEASE TYR AGAING !\n"; + return 1; + } + } + + in.open(Log_file); //start the file first + if(!out.is_open()) //if the file which called "Log_file" not start, the code will create for the file which called "pswd.log" + { + 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 << " ]" << " Empty Log was created!" << std::endl; //Wrote in pswd.log + } + in.close(); + out.close(); + + return 0; +} \ No newline at end of file diff --git a/main.exe b/main.exe new file mode 100644 index 0000000..c04dd64 Binary files /dev/null and b/main.exe differ diff --git a/variable.h b/variable.h new file mode 100644 index 0000000..c67c826 --- /dev/null +++ b/variable.h @@ -0,0 +1,27 @@ +#include +#include // Only can used create file but if file path not exists it will faild for action +#include // IO format setup +#include // Create file Path if doesn't exist,but it can't write the files +#include // system time +#include //Windows API +//#include //Unix and Linux API + +//std::string log_File_Path = "file_log.log"; +std::ifstream in; +std::ofstream out; + +time_t log_wrote_time = time(0); //Get the time from now +struct tm *ltm = localtime(&log_wrote_time); //Get the structure from time of local + +std::string Log_Directory = "./Log/"; +std::string Log_file = Log_Directory + "pswd.log"; + +std::string str_password = ""; //saved password +std::string check_str_password = ""; //check password +int times_for_locked = 3; //3 times for opportunity and for try to lock the secure-lock +char option; // CLI of option +/* + Note: + "return 0" is normal status + "return 1" is error status +*/ \ No newline at end of file diff --git a/while.cpp b/while.cpp new file mode 100644 index 0000000..a757783 --- /dev/null +++ b/while.cpp @@ -0,0 +1,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 + } + } +} \ No newline at end of file diff --git a/while.exe b/while.exe new file mode 100644 index 0000000..c467f70 Binary files /dev/null and b/while.exe differ