-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include <iostream> | ||
#include <fstream> // Only can used create file but if file path not exists it will faild for action | ||
#include <iomanip> // IO format setup | ||
#include <filesystem> // Create file Path if doesn't exist,but it can't write the files | ||
#include <ctime> // system time | ||
#include <windows.h> //Windows API | ||
//#include <unistd.h> //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 | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} | ||
} |