How would I hide a password string for my log in system?

I have a login system in place for my new admin command system, and I want to make it look as realistic as possible. One thing I would like to achieve is to have any text typed in the player ‘hidden’, replaced by asteriks like most modern password systems do, while still saving the text typed in to a variable to be fired to the server for checks. For more clarity, let me visualise a bit more.

Clarifiying doubts
So lets say the player was to type in a rather generic password like so:

JeffLol

What I’d like to achieve is to have the textbox display this:

*******

While still saving the actual password string (JeffLol) to a variable to be fired to the server to verify whether the password matches or not.

Any ideas?
Log-In System (Client Code)

local remoteEvent = game.ReplicatedStorage.verifyPassword
script.Parent.FocusLost:Connect(function(hasEntered)
	if hasEntered then
		local PasswordRecieved = script.Parent.Text
		if PasswordRecieved ~= "" then
			game.ReplicatedStorage.verifyPassword:FireServer(PasswordRecieved)
		else
			script.Parent.Parent.Parent.Instruction.TextLabel.Text = "Please Enter Your Password"
			script.Parent.Parent.Parent.Instruction.TextLabel.TextColor3 = Color3.new(1, 0, 0)
			wait(2)
			script.Parent.Parent.Parent.Instruction.TextLabel.TextColor3 = Color3.new(1, 1, 1)
		end
		
		script.Parent.Text = "" --Set it to nil
		print("Sent Password To Be Verified")
	else
		print("Player Pressed Other Key")
	end
end)

remoteEvent.OnClientEvent:Connect(function(wasVerified)
	if wasVerified then
		script.Parent.Parent.Parent.Instruction.TextLabel.Text = "Successfully Logged In"
		script.Parent.Parent.Parent.Instruction.TextLabel.TextColor3 = Color3.new(0, 1, 0)
		script.Parent.Parent.Parent.Parent:TweenPosition(UDim2.new({0.301, 0},{1, 0}), Enum.EasingDirection.Out, Enum.EasingStyle.Quad, 3, false)
		print("Done!")
	else
		script.Parent.Parent.Parent.Instruction.TextLabel.Text = "Incorrect, Please Contact JeffTheEpicRobloxian For Assistance. An Automatic Resetting System Will Come Eventually"
		script.Parent.Parent.Parent.Instruction.TextLabel.TextColor3 = Color3.new(1, 0, 0)
		print("Failed!")
		wait(2)
		script.Parent.Parent.Parent.Instruction.TextLabel.TextColor3 = Color3.new(1, 1, 1)
	end
end)

The best way would be to store the password on the server and use a RemoteFunction that just returns a Boolean to check the password.

You could update an internal string variable and replace the text it with the corresponding amount of *

2 Likes

I do have a module in server storage that stores all the passwords and userIds corresponding with it, but when I make future improvements, I will use your method

1 Like

The easiest way would probably be to have a transparent textbox where the user actually types, and then have the underlying (visible) one show the asterisks. It wouldn’t be perfectly aligned, but something like:

local asterisksBox = script.Parent.AsterisksTextBox -- visible TextLabel
local entryBox = script.Parent.InputTextBox -- invisible TextBox

entryBox:GetAttributeChangedSignal("Text"):Connect(function()
    asterisksBox.Text = string.rep("*", string.len(entryBox.Text))
end)

Could maybe be serviceable.

The other option would be to keep track of the typed text in a variable as it changes, and overwrite the actual Text. That would be a huge pain to get right though - what if someone deletes an asterisk in the middle of the box? What do you do?

1 Like

Hmmm. Is it possible to insert all the characters into a table as they type, replacing the letter with an asteriks, before (when they press enter) combining all the characters together before firing the complete string to the server? Because I want to avoid overlapping text boxes if possible. And if this is possible, what should I use?

Maybe? With some combination of GetAttributeChangedSignal("Text") and CursorPosition / SelectionStart? But honestly at that point I would just use a TextLabel and custom-implement your own “text box” with InputBegan. Like, manually turn keypresses into text and show asterisks representing the internal text.

1 Like

Ok! I will try that! Thanks for your help

It will be very hard, UserInputService | Documentation - Roblox Creator Hub won’t really work for upper/lower-case keys, and KeyboardService | Documentation - Roblox Creator Hub doesn’t seem to have any methods.

So now you need to track the Shift key… and Alt codes… and Delete vs. Backspace… I don’t know that this is a road you want to go down to be honest :slight_smile:

I still think hacking an invisible TextBox is the right way to go

1 Like

Don’t worry I took your advice for the overlapping thing and it works perfectly well! Thank you so much for your help!

1 Like