Trying to censor TextBox text?

Hi! I am working on a CAD System and I am trying to make the Login Screen password censor to a Asterisk ( * ) every second. I have been trying to find a way but I just can’t get it to work. I’ve also got it in a wait(1) so I can’t save the text as a local or else it’ll just save as an asterisk already… What i’ve got is as follows;

while wait(1) do

local TextBox = LoginScreen.pass
TextBox.Text = string.rep("*", #TextBox.Text)

end

Thank you for your help!

1 Like

Easiest way is to make a separate textbox that is where the user actually types the password (with transparency 1), and then display stars on the visible textbox.

That aside, why do you even need username/password system? This is against Roblox terms of service, as far as I am aware.

1 Like

The username/password system doesn’t use the users actual passwords. It compares to a table of usernames/passwords in the script.

Instead of using a while loop (which by the way, using wait for a condition is disgusting), you can mask the TextBox as users type. I’m not really sure why you want to do this at all though, aesthetic aside? It’s not like people will see said password. If they do, that’s a design flaw to address.

local TextBox = LoginScreen.pass

TextBox:GetPropertyChangedSignal("Text"):Connect(function ()
    TextBox.Text = string.rep("*", #TextBox.Text)
end)

That being said, well, this doesn’t address the issue of being able to access the raw text while having your TextBox masked. Perhaps you want to mask it after focus is lost?

3 Likes

You could store the original text in a value before masking it?

If the value is relevant to keep then ideally you should store the text before masking. If the value isn’t relevant for later use then no you don’t need to keep it and it can remain purely an aesthetic feature (but honestly in that case, just have your code automatically type it out or don’t use the screen at all).

you could also make a fake text box (text label) on top of the password textbox and set the password textbox text transparency to 1
then when the script detect changes on the password textbox, it adds the ( * ) to the fake textbox

local TextBox = LoginScreen.pass
local FakeTextBox = LoginScreen.TextLabel

TextBox:GetPropertyChangedSignal("Text"):Connect(function ()
    FakeTextBox.Text = string.rep("*", #TextBox.Text)
end)

I’m not sure if that’s a real option since I’ve never tested it but I personally don’t see a point in adding a dummy TextLabel when you already have a text object that you can manipulate for this purpose. You’re more likely to design your Gui in mind with that TextBox being a part of your Gui.

Dummy objects have other purposes but in this case it’s fairly unnecessary.

I tried and it worked great.

If you have the dummy textlabel then you can have options like show/hide password

like

local TextBox = LoginScreen.pass
local FakeTextBox = LoginScreen.TextLabel
local ShowPassword = LoginScreen.Showpass

TextBox:GetPropertyChangedSignal("Text"):Connect(function ()
    FakeTextBox.Text = string.rep("*", #TextBox.Text)
end)

ShowPassword.MouseButton1Click:Connect(function()
    if ShowPassword.Text == "Show" then
        ShowPassword.Text = "Hide"
        TextBox.TextTransparency = 1
        FakeTextBox.Visible = true
    else
        ShowPassword.Text = "Show"
        TextBox.TextTransparency = 0
        FakeTextBox.Visible = false
    end
end

make sure the fake text box background transparency is 1

The point I’m making isn’t about whether or not it works, it’s about the necessity of actually doing that - please read my post carefully before replying. I simply don’t think it’s necessary to add a dummy text box when you already have one to work with in which you can apply masking on. This is also reminiscent of masking behaviour on browser/application window text boxes so I see no need to treat it differently on Roblox.

You’re free to use your own solution for your project though if you feel that would be easier or more appropriate, even though in some circumstances one solution can be objectively worse than another or it’s just a simple matter of approach. Thanks for sharing an alternate way to accomplish this!

the message I replied isn’t about it works, becausee you said it’s unnecessary so I wanted to proof that it work and it is necessary to do that

I understand it works because I know how to pull it off. You don’t have to prove anything; this isn’t about a right or wrong. Please read my point carefully! It is not necessary to make a dummy textbox!

What I am saying is that because you already have a textbox that you can manipulate, it seems unnecessary to go with a long winded solution of setting up a dummy textbox to render the masked text for you. Replacing all the characters of a textbox as you type is an inexpensive and quick operation and it is equally easy to unmask characters if you track the writing. This is under the assumption that you need the text that’s being typed.

Real textboxes on websites and application windows apply masking directly to the textbox. Therefore, I do not see a reason to treat the solution differently on Roblox by creating a dummy textbox to render masked text over directly manipulating the textbox. This is what I’m saying.

I very clearly made this explanation in my last post. It’s not about whether it works or not and there’s nothing to prove. I simply don’t think you need a dummy textbox when you can mask the preexisting textbox (you also lose out on things like highlighting that’s specific to a textbox and not to a text label). If you want to use this for your own project though, feel free to do so. :slight_smile:

1 Like