/* Thor Server 2.0 Project - Codenamed "Stockholm" Copyright 2008 - 2009 Joe Hegarty This file is part of The Thor Server 2.0 Project - Codenamed "Stockholm". The Thor Server 2.0 Project - Codenamed "Stockholm" is free software: you can redistribute it and/or modify it under the terms of the Microsoft Public License The Thor Server Project is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Microsoft Public License for more details. You should have received a copy of the Microsoft Public License along with The Thor Server Project. If not, see http://www.opensource.org/licenses/ms-pl.html */ using System; using System.Text.RegularExpressions; namespace StockholmLibrary.Game.Util { //------------------------------------ public class DataValidator { public const int USER_NAME_MINLEN = 3; public const int USER_NAME_MAXLEN = 15; public const string USER_NAME_ALLOWED = "1234567890qwertyuiopasdfghjklzxcvbnm-+=?!@:.,$"; public const string POOL_FIGURE_REGEX = "(^ch=s0[1-2]/(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9][0-9]),(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9][0-9]),(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9][0-9])){1}$"; public const int USER_PASSWORD_MINLEN = 5; public const int USER_PASSWORD_MAXLEN = 10; //********************************************** public bool ValidateUsername(string username) { // Validate length if (username == null || username.Length < USER_NAME_MINLEN || username.Length > USER_NAME_MAXLEN) { return false; } // Validate allowed characters foreach (char chr in username.ToLower()) { if (USER_NAME_ALLOWED.IndexOf(chr) == -1) { return false; } } // Name is a valid username return true; } //********************************************** public bool ValidateUserPassword(string username, string password) { // Not the same as username? if (username != password) { // Valid length? if (password.Length >= USER_PASSWORD_MINLEN && password.Length <= USER_PASSWORD_MAXLEN) { return true; } } return false; } //********************************************** public bool ValidateUserFigure(string figure) { return true; } //********************************************** public bool ValidatePoolFigure(string figure) { Regex regex = new Regex(POOL_FIGURE_REGEX); Match match = regex.Match(figure); return match.Success; } } }