65,186
社区成员




static bool verifyToken(const char * token, std::string &strout)
{
ws_config& conf = getConfig();
if(!conf.authen) {
if(Daemon::IsDebug()) {
std::cout << "Token authen is disabled!" << std::endl;
}
return true;
}
if(NULL == token || '\0' == *token) {
std::cerr << "Token is null or empty!" << std::endl;
strout = "Token is null or empty!";
return false;
}
std::string str = CRijndaelUtil::getDecryptedStr(token);
unsigned int found = str.find_first_of(CRijndaelUtil::getDelimitStr());
if(found != std::string::npos) {
if(!conf.dbauthen) {
if(Daemon::IsDebug()) {
std::cout << "Token database authen is disabled!" << std::endl;
}
return true;
}
std::string name = str.substr(0, found);
std::string pwd = str.substr(found + CRijndaelUtil::getDelimitStr().size());
// retrieve user's password from database.
std::string pwdindb;
if(getDbUserPwd(pwdindb, name, conf.host.c_str(), conf.username.c_str(), conf.password.c_str(),
conf.dbname.c_str(), conf.port, conf.timeout)) {
if(pwdindb == CMiscUtil::getMD5(pwd)) {
if(Daemon::IsDebug()) {
std::cout << "Token database authentication success!" << std::endl;
}
return true;
} else {
std::cerr << "Password is not correct!" << std::endl;
strout = "Password is not correct!";
}
} else {
std::cerr << "Failed to read password from database!" << std::endl;
strout = "Failed to read password from database!";
}
} else {
std::cerr << "Invalid token format!" << std::endl;
strout = "Invalid token format!";
return false;
}
return false;
}