mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-08 15:28:42 +00:00
allow hyphens in usernames
This commit is contained in:
parent
959cc08224
commit
6e3e51611f
@ -392,13 +392,18 @@ bool string_bool(const std::string& str,bool def)
|
|||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isvalid_char(char c)
|
||||||
|
{
|
||||||
|
return ((c == '_') || (c == '-'));
|
||||||
|
}
|
||||||
|
|
||||||
//! Check if the username is valid
|
//! Check if the username is valid
|
||||||
//! (all alpha-numeric plus underscore)
|
//! (all alpha-numeric plus underscore and hyphen)
|
||||||
bool isvalid_username(const std::string& username)
|
bool isvalid_username(const std::string& username)
|
||||||
{
|
{
|
||||||
const size_t alnum = std::count_if(username.begin(),username.end(),isalnum);
|
const size_t alnum = std::count_if(username.begin(),username.end(),isalnum);
|
||||||
const size_t underscore = std::count(username.begin(),username.end(),'_');
|
const size_t valid_char = std::count_if(username.begin(),username.end(),isvalid_char);
|
||||||
if((alnum + underscore != username.size()) || underscore == username.size() || username.empty() ) {
|
if((alnum + valid_char != username.size()) || valid_char == username.size() || username.empty() ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -658,11 +658,11 @@ void server::process_login(const network::connection sock, const config& data)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the username is valid (all alpha-numeric plus underscore)
|
// Check if the username is valid (all alpha-numeric plus underscore and hyphen)
|
||||||
std::string username = (*login)["username"];
|
std::string username = (*login)["username"];
|
||||||
if(!utils::isvalid_username(username)) {
|
if(!utils::isvalid_username(username)) {
|
||||||
network::send_data(construct_error(
|
network::send_data(construct_error(
|
||||||
"This username contains invalid characters. Only alpha-numeric characters and underscores are allowed."),sock);
|
"This username contains invalid characters. Only alpha-numeric characters, underscores and hyphens are allowed."),sock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user