You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
915 B
29 lines
915 B
#include "include/auth.h"
|
|
|
|
namespace meg {
|
|
|
|
Auth::Auth() {
|
|
// 小学 张三1..3
|
|
users_[L"张三1"] = {L"123", Level::Primary};
|
|
users_[L"张三2"] = {L"123", Level::Primary};
|
|
users_[L"张三3"] = {L"123", Level::Primary};
|
|
|
|
// 初中 李四1..3
|
|
users_[L"李四1"] = {L"123", Level::Middle};
|
|
users_[L"李四2"] = {L"123", Level::Middle};
|
|
users_[L"李四3"] = {L"123", Level::Middle};
|
|
|
|
// 高中 王五1..3
|
|
users_[L"王五1"] = {L"123", Level::High};
|
|
users_[L"王五2"] = {L"123", Level::High};
|
|
users_[L"王五3"] = {L"123", Level::High};
|
|
}
|
|
|
|
std::optional<User> Auth::authenticate(const std::wstring& username, const std::wstring& password) const {
|
|
auto it = users_.find(username);
|
|
if (it == users_.end()) return std::nullopt;
|
|
if (it->second.first != password) return std::nullopt;
|
|
return User{username, password, it->second.second};
|
|
}
|
|
|
|
} // namespace meg
|