/// <summary> /// </summary> /// <param name="obj"> /// </param> /// <returns> /// </returns> private static bool CheckAddUserParameters(string[] obj) { if (obj.Length != 9) { Console.WriteLine( "Wrong number of parameters supplied. <username> <password> <number of characters> <expansions> <gm level> <email> <first name> <last name>"); return(false); } bool failed = false; int temp = 0; if (!int.TryParse(obj[3], out temp)) { Console.WriteLine("Error: <number of characters> must be a number (duh!)"); failed = true; } if (!int.TryParse(obj[4], out temp)) { Console.WriteLine("Error: <expansions> must be a number between 0 and 2047!"); failed = true; } else { if ((temp < 0) || (temp > 2047)) { Console.WriteLine("Error: <expansions> must be a number between 0 and 2047!"); failed = true; } } if (!int.TryParse(obj[5], out temp)) { Console.WriteLine("Error: <GM Level> must be number between 0 and 511"); failed = true; } else { if ((temp < 0) || (temp > 511)) { Console.WriteLine("Error: <GM Level> must be number between 0 and 511"); failed = true; } } if (!TestEmailRegex.TestEmail(obj[6])) { Console.WriteLine("Error: <Email> You must supply an valid email address for this account"); failed = true; } return(!failed); }
private string RegisterAccount(List <string[]> split) { /* * NOT SQL-INJECTION SAFE YET! * * To do: Add sql-checks for entries */ // Check wether everything is filled in or not. if (!string.IsNullOrEmpty(split[1][1]) && !string.IsNullOrEmpty(split[2][1]) && !string.IsNullOrEmpty(split[3][1]) && !string.IsNullOrEmpty(split[4][1]) && !string.IsNullOrEmpty(split[5][1]) && !string.IsNullOrEmpty(split[6][1])) { if (!LoginDataDao.Instance.Exists(split[2][1])) { // Check Email format if (TestEmailRegex.TestEmail(split[1][1])) { if (split[5][1] == split[6][1]) { DBLoginData dbchar = new DBLoginData(); dbchar.AccountFlags = 0; dbchar.AllowedCharacters = 12; dbchar.CreationDate = DateTime.Now; dbchar.Email = split[1][1]; dbchar.Expansions = 2047; dbchar.FirstName = split[3][1]; dbchar.Flags = 0; dbchar.GM = 0; dbchar.LastName = split[4][1]; dbchar.Password = new LoginEncryption().GeneratePasswordHash(split[5][1]); dbchar.Username = split[2][1]; CellAO.Database.Dao.LoginDataDao.Instance.Add(dbchar); Console.WriteLine("Account created."); return("Account created."); } return("Passwords are not matching, please retry."); } return("Email is wrong, please retry."); } return("Username is already taken, please retry."); } else { return("n/a"); } }
/// <summary> /// </summary> /// <param name="obj"> /// </param> private static void AddUser(string[] obj) { if (obj.Length == 1) { List <string> temp = new List <string>(); temp.Add("adduser"); while (true) { Console.Write("Username: "******"Please enter a username (at least 6 chars)..."); continue; } if (CheckUsername(test)) { temp.Add(test); break; } } while (true) { Console.Write("Password: "******"Please enter a password (at least 6 chars) for your safety..."); continue; } temp.Add(test); break; } while (true) { Console.WriteLine("Number of character slots: "); string test = Console.ReadLine(); if (IsNumber(test)) { temp.Add(test); break; } } Console.WriteLine("Expansions: Enter 2047 for all expansions (i know you want that)"); while (true) { Console.Write("Expansions: "); string test = Console.ReadLine(); if (IsNumber(test)) { temp.Add(test); break; } } Console.WriteLine( "GM-Level: Anything above 0 is GM, but there are differences. Full Client GM = 1 (using keyboard shortcuts) but for some items you have to be GM Level 511"); while (true) { Console.Write("GM-Level: "); string test = Console.ReadLine(); if (IsNumber(test)) { temp.Add(test); break; } } while (true) { Console.WriteLine("E-Mail: "); string test = Console.ReadLine(); if (TestEmailRegex.TestEmail(test)) { temp.Add(test); break; } } Console.Write("First name: "); temp.Add(Console.ReadLine()); Console.Write("Last name: "); temp.Add(Console.ReadLine()); obj = temp.ToArray(); } Colouring.Push(ConsoleColor.Red); bool argsOk = CheckAddUserParameters(obj); Colouring.Pop(); if (!argsOk) { return; } DBLoginData login = new DBLoginData { Username = obj[1], AccountFlags = 0, AllowedCharacters = int.Parse(obj[3]), CreationDate = DateTime.Now, Email = obj[6], Expansions = int.Parse(obj[4]), FirstName = obj[7], LastName = obj[8], GM = int.Parse(obj[5]), Flags = 0, Password = new LoginEncryption().GeneratePasswordHash(obj[2]) }; try { LoginDataDao.WriteLoginData(login); } catch (Exception ex) { Colouring.Push(ConsoleColor.Red); Console.WriteLine( "An error occured while trying to add a new user account:" + Environment.NewLine + "{0}", ex.Message); Colouring.Pop(); return; } Colouring.Push(ConsoleColor.Green); Console.WriteLine("User added successfully."); Colouring.Pop(); }