Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

334 46 劉泰廣 955470 #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions LoginSystem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include <iostream>
#include <vector>
using namespace std;

void registor();
void login();
void change();

vector<string> accounts;
vector<string> passwords;
vector<string> changepassword;

int main() {
while (true) {
cout << "註冊(1) 或 登入(2) 或 改密碼(3)\n";
char option;
cin >> option;

if (option == '1') {
registor();
} else if (option == '2') {
login();
} else if (option == '3') {
change();
} else {
cout << "無效的指令,請重新輸入:\n";
}
}
}

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;
}
}
}