Fitlering text without player intput

So I made a module script that has a function :GetPass(len) that returns a random string of upper and lowercase letters, numbers, and special characters like %.

local pass = {}

local chars = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","#","$","%","^","@","&","*","-","_","!","~"}

local max = 10000 --Max amount of characters, 10000 is the recommended so that it won't take forever to generate.


function pass:GetPass(len)
	local Pass = ""
	
	if len  >= max then
		return false
	end
	
	for i = 1, tonumber(len), 1 do
		wait() --Needed for long password or lower-end computers. Otherwise, it would try to do it super fast and would cause problems if it is a long pass.
		local cap = math.random(1,2)
		local char = math.random(1,2)
		local num = math.random(1,9)
		
		if char == 1 then
			if cap == 1 then
				Pass = Pass..string.upper(chars[math.random(1,#chars)])
			else
				Pass = Pass..string.lower(chars[math.random(1,#chars)])
			end
		else
			Pass = Pass..num
		end
		
	end
	
	Pass = chars[math.random(27,#chars)]..Pass..chars[math.random(27,#chars)]
	
	return Pass
	
end

return pass

But then I read an article: https://developer.roblox.com/en-us/articles/Text-and-Chat-Filtering that made me think that I should filter the random string to make sure it doesn’t make any inappropriate message on accident. How would I do that, because Text Service says it requires a user id. And the filtered text dose not come from player input. So how would I filter it.

The real question is why you’re setting up a password system when other unique identifiers exist for your usage.

Frankly, something like this would be as simple as passing a UserId as a parameter to GetPass and using that as the target filter UserId.

There’s a very good article in the wiki about this. It’s actually in the same link that you posted. It describes exactly what you should do for random strings.

1 Like

I have two suggestions;

Remove all vowels so the words won’t make sense, and separate numbers

Use HttpService to generate Unique GUIDs

But I don’t see why you can’t Filter the String for the User you are showing it to, or you could just use something else like Broadcast method

I used this module in a game I made where there would be a door that generated a short password that you would have to find hidden in the map. You would input the password and the door would open.

2 Likes

In a case like his, where he is randomly generating smaller “passwords” for the user to quickly jot down or simply remember, a GUID probably isn’t the best solution. Removing vowels and separating numbers isn’t enough, though. There are vowel-less phrases that could be construed as swear words. The best way to handle his situation is listed in the exact wiki article that he posted. Here’s a permalink to the correct solution: Text Filtering | Documentation - Roblox Creator Hub

Yes, GUID is long but you can always decide to cut it with string:sub, I’m pretty sure the OP can figure that out

I also recommend him to use the Filter as well but I appreciate the thought.

GUID’s are not filtered, and should not be treated as such. There is still a slim possibility that a product of HttpService:GenerateGUID could include something that could be construed as a swear word.

Wouldn’t that be Roblox’s responsibility? We are simply using a function they provided

I understand that you recommend strongly for the OP to use the Filter and I agree, I think he got the point.

The article does say what to do with random strings, but it displays a message for the player. And it uses their user id as a parameter, “TextService:FilterStringAsync(text, userid).”
So what would I put as the user id?

In short, you use the UserId of the player viewing the message. Please take a look at the code and example place that the wiki provided.

You should also make sure to regenerate the passphrase if it is filtered, so your users aren’t left with an unusable passphrase.

Ok, for the function I will add a parameter for the player viewing the password and I will also regenerate the password if it is filtered.

1 Like