r/badcode • • Oct 06 '21

sql So umm this is from Twitch source code leak . NSFW

Post image
2.9k Upvotes

400 comments sorted by

View all comments

Show parent comments

6

u/IAmTheSysGen Oct 07 '21 edited Oct 07 '21

Man, it's pretty easy to read from a file each line in a for loop.

You can also easily refactor this code. Copy the lines to a banlist.txt file.

Do a search and replace "OR ue.login LIKE " with ""

Do a simple

file = open("banlist.txt")
for (line in file):
    if( re.match( ue.login, line )):
        rejectUsername()

Or if you want to be as efficient as the OP

file = open("banlist.txt")
if (re.match("|".join(file.readlines()), ue.login)):
    rejectUsername()

It should take at most 15 minutes to refactor the code above into the proper way (tm).

0

u/d_thinker Oct 07 '21

So opening a file each time user tries to sign up, going through each line of the file that gets bigger every day and doing regex match against each line? OK, I see you didn't write anything at scale.

3

u/IAmTheSysGen Oct 07 '21

You know you can just keep the file open, right? You don't have to open and close it for every user.

You're not matching regex against every line. Read the last code block carefully. You're creating one regex that matches every line in the file simultaneously.