allow hyphens in usernames
This commit is contained in:
parent
959cc08224
commit
6e3e51611f
2 changed files with 10 additions and 5 deletions
|
@ -392,13 +392,18 @@ bool string_bool(const std::string& str,bool def)
|
|||
return def;
|
||||
}
|
||||
|
||||
bool isvalid_char(char c)
|
||||
{
|
||||
return ((c == '_') || (c == '-'));
|
||||
}
|
||||
|
||||
//! 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)
|
||||
{
|
||||
const size_t alnum = std::count_if(username.begin(),username.end(),isalnum);
|
||||
const size_t underscore = std::count(username.begin(),username.end(),'_');
|
||||
if((alnum + underscore != username.size()) || underscore == username.size() || username.empty() ) {
|
||||
const size_t valid_char = std::count_if(username.begin(),username.end(),isvalid_char);
|
||||
if((alnum + valid_char != username.size()) || valid_char == username.size() || username.empty() ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -658,11 +658,11 @@ void server::process_login(const network::connection sock, const config& data)
|
|||
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"];
|
||||
if(!utils::isvalid_username(username)) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue