User login

Hi, I am working on a simple User login phase for my game. I want to know how to reject the entered user name or password if (a) It already exists in the registeredUsers Array, and (b) if the user or password has any dissallowed characters i.e “@, #, ~, space” etc.
here is my code right now:

var userName : String;
var userPassword : String;

var registeredUsers : Array = new Array();

function OnGUI()
{
	GUI.Label(Rect(10, 15, 100, 40), "User Name");
	userName = GUI.TextField(Rect(10, 40, 150, 20), userName, 20);
	
	GUI.Label(Rect(10, 80, 100, 40), "Password");
	userPassword = GUI.PasswordField (Rect (10, 105, 150, 20), userPassword, "*"[0], 20);
	
	if(GUI.Button(Rect(10, 150, 100, 20), "Create user"))
	{
		registeredUsers.Push(userName + ":" + userPassword);
	}
	if(GUI.Button(Rect(525, 10, 100, 20), "Clear"))
	{
		registeredUsers.clear();
	}
	
	var str = Array(registeredUsers).Join("

");

 	GUI.Box(Rect(200, 10, 300, 300), str);	

    }

Many thanks
-TG106

I personally am not a Regex fan, but that may be the best? In any case, you can use Contains String.Contains Method (System) | Microsoft Learn to check for what’s in a string. Then just don’t push it if it contains any of those characters.

You can look at each element of the array to compare against the input, and reject if found. Or use another type of array (list, hash, etc.) which have handy function that basically do that for you

var addIt = true;
for (entry : String in registeredUsers)
   if (entry == userName)
        addIt = false;
if (addIt)
   registeredUsers.push(userName);