-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauth.cpp
More file actions
31 lines (26 loc) · 883 Bytes
/
Copy pathauth.cpp
File metadata and controls
31 lines (26 loc) · 883 Bytes
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
#include <iostream>
#include <fstream>
#include <unordered_map>
#include <string>
#include <tuple>
using namespace std;
unordered_map<string, tuple<string, double, string>> loadUsers(const string &filename)
{
unordered_map<string, tuple<string, double, string>> users;
ifstream file(filename);
string account, pin, transactions;
double balance;
while (file >> account >> pin >> balance)
{
getline(file, transactions);
if (!transactions.empty() && transactions[0] == ' ')
transactions = transactions.substr(1);
users[account] = make_tuple(pin, balance, transactions);
}
return users;
}
bool authenticate(const unordered_map<string, tuple<string, double, string>> &users, const string &account, const string &pin)
{
auto it = users.find(account);
return it != users.end() && get<0>(it->second) == pin;
}