• Welcome to Valhalla Legends Archive.
 

Detecting if a username has an illegal character in it...

Started by Hero, April 22, 2006, 08:36 PM

Previous topic - Next topic

Hero

How would I detect if a username has an illegal character in it?  When the bot recieves EID_SHOWUSER, I want it to add to the listview the usernames with illegal characters in it. Right now I have no idea where to start. Any positive tips would help, thanks.

topaz

RLY...?

Hero

Something like:

if instr(1,strusername,illy_character,vbTextCompare) then add user to list?

rabbit

Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.

Joe[x86]

/**
Checks if a Battle.net account name is legal<br />
Make sure you remove @gateway, if it's there.<br />
If you're using D2, also remove the CharName* mangaling at the beginning
@author J
@param name Account name
@return Validity (boolean)
*/
boolean isLegalAccoutName(String name)
{
// Temporary variable declaration
boolean tempValid = false;

// Check length
if(name.length() !>= 3)
{
return false;
}

// Check if the first char is an alpha char
String legalFirstChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXZY";
for(int j = 0; j < legalFirstChars.length(); j++)
{
if(name.charAt(0) == legalFirstChars.charAt(j))
{
tempValid = true;
}
}
if(tempValid != true)
{
return false;
}

// Check if the rest are legal
String legalChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.[]-_()";
for(int i = 1; i < name.length(); i++)
{
tempValid = false;
for(int j = 0; j < legalChars.length(); j++)
{
if(name.charAt(i) == legalChars.charAt(j))
{
tempValid = true;
}
}
if(tempValid == false)
{
return false;
}
}
return true;
}


EDIT -
That's obviously not all the valid characters, but the algorithm is there.

EDIT -
Checking that first character is alpha, and checking length (thanks Frozen). I may have all the valid characters now.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

FrOzeN

I just wrote this function, it should work for determining if it's an illy or not. There's probably an easier way to write this, I rushed it so eh..

Note that it doesn't have an error handling for usernames longer than 15 characters or a just 1 character. It treats them as legal names. Though, assuming you use this function correctly there isn't a need to have it handle them.

Public Function IsIlly(Username As String) As Boolean
    If Len(Username) = 2 Then
        IsIlly = True
        'Username to short
    Else
        Dim strUsername As String, i As Integer, badChar As Boolean, strIllegal As String, strExtra As String
        strUsername = LCase(Username)
        strIllegal = "`~!@$^&=+|{};:',"
        strExtra = "-_()[]."
       
        If InStr(1, strExtra, Left(LCase(Username), 1)) <> 0 Then
            IsIlly = True
            'First character isn't letter/number
        Else
            For i = 1 To Len(strUsername)
                If InStr(1, strIllegal, Mid(strUsername, i, 1)) <> 0 Then
                    IsIlly = True
                    'Contains illegal character
                ElseIf InStr(1, strExtra, Mid(strUsername, i, 1)) <> 0 Then
                    If badChar <> False Then
                        IsIlly = True
                        'Two non-letter/number characters in a row.
                    Else
                        badChar = True
                    End If
                Else
                    badChar = False
                End If
            Next i
        End If
    End If
End Function


[EDIT] Slight clean up.
[EDIT 2] Added " | " to illegal character string.
~ FrOzeN

Hero

First time I got no negative replies, thank you all  ;D

Joe[x86]

Oh yeah, forgot the negative reply.

Duh, you should know how to do this before writing a bot!

Heh, kidding.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.