From e0989d166402ae91f95affd570c4117865ef324a Mon Sep 17 00:00:00 2001 From: IaintHamburger <112560102+IaintHamburger@users.noreply.github.com> Date: Sun, 23 Apr 2023 22:31:29 +0800 Subject: [PATCH 1/2] Create LoginSystem.cpp --- LoginSystem.cpp | 81 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 LoginSystem.cpp diff --git a/LoginSystem.cpp b/LoginSystem.cpp new file mode 100644 index 0000000..544a61e --- /dev/null +++ b/LoginSystem.cpp @@ -0,0 +1,81 @@ +#include +#include +using namespace std; + +void registor(); +void login(); +void change(); + +vector accounts; +vector passwords; +vector changepassword; + +int main() { + while (true) { + cout << "註冊(1) 或 登入(2) 或 改密碼(3)\n"; + char option; + cin >> option; + + if (option == '1') { + registor(); + } else if (option == '2') { + login(); + } else { + change(); + } + } +} + +void registor() { + cout << "請輸入帳號:\n"; + string input_account; + cin >> input_account; + accounts.push_back(input_account); + + cout << "請輸入密碼:\n"; + string input_password; + cin >> input_password; + passwords.push_back(input_password); +} + +void login() { + cout << "請輸入帳號:\n"; + string login_account; + cin >> login_account; + + cout << "請輸入密碼:\n"; + string login_password; + cin >> login_password; + + bool found = false; + for (int i = 0; i < accounts.size(); i++) { + if (login_account == accounts[i] && login_password == passwords[i]) { + cout << "歡迎第" << i + 1 << "個使用者\n"; + found = true; + break; + } + } + if (found == false) { + cout << "無效的帳號或密碼\n"; + } +} +void change() { + cout << "請輸入帳號:\n"; + string login_account; + cin >> login_account; + + cout << "請輸入密碼:\n"; + string login_password; + cin >> login_password; + + bool found = false; + for (int i = 0; i < accounts.size(); i++) { + if (login_account == accounts[i] && login_password == passwords[i]) { + cout << "請輸入你想改的密碼:\n"; + string newpassword; + cin >> newpassword; + passwords[i] = newpassword; + } + } +} + From 6f9120f628d1c69bf24c41ecd0c7cb6ebd1969aa Mon Sep 17 00:00:00 2001 From: IaintHamburger <112560102+IaintHamburger@users.noreply.github.com> Date: Thu, 27 Apr 2023 19:09:28 +0800 Subject: [PATCH 2/2] Update LoginSystem.cpp --- LoginSystem.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/LoginSystem.cpp b/LoginSystem.cpp index 544a61e..4d1b9d8 100644 --- a/LoginSystem.cpp +++ b/LoginSystem.cpp @@ -20,9 +20,11 @@ int main() { registor(); } else if (option == '2') { login(); - } else { + } else if (option == '3') { change(); - } + } else { + cout << "無效的指令,請重新輸入:\n"; + } } }