From 6e3e51611f1c22629fce9226a37278dec364afcf Mon Sep 17 00:00:00 2001 From: Gunter Labes Date: Thu, 18 Oct 2007 11:47:17 +0000 Subject: [PATCH] allow hyphens in usernames --- src/serialization/string_utils.cpp | 11 ++++++++--- src/server/server.cpp | 4 ++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/serialization/string_utils.cpp b/src/serialization/string_utils.cpp index 735e4b1ad2d..d5592700742 100644 --- a/src/serialization/string_utils.cpp +++ b/src/serialization/string_utils.cpp @@ -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; diff --git a/src/server/server.cpp b/src/server/server.cpp index 995051d05bd..77ef153fcd7 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -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; }