29 lines
830 B
C++
29 lines
830 B
C++
//
|
|
// Created by dongl on 23-4-23.
|
|
//
|
|
|
|
#include "UserService.h"
|
|
#include <experimental/random>
|
|
|
|
mp::sri* UserService::login(uint64_t account, const std::string& password) {
|
|
return userDb.login(account, password);
|
|
}
|
|
|
|
mp::sri* UserService::register_(uint64_t account, const std::string &password) {
|
|
// 生成salt
|
|
std::string password_salt;
|
|
for (int i = 0; i < std::experimental::randint(5, 8); ++i) {
|
|
password_salt.push_back((char )std::experimental::randint(33, 126));
|
|
}
|
|
|
|
// 加密密码 生成hash
|
|
std::string source = std::to_string(account) + password + password_salt;
|
|
size_t password_hash = std::hash<std::string>()(source);
|
|
|
|
return userDb.register_(account, std::to_string(password_hash), password_salt);
|
|
}
|
|
|
|
mp::sri* UserService::logout(uint64_t account) {
|
|
return nullptr;
|
|
}
|