Derma password text entry?

I’m trying to make a password box (Eg. the value is hidden, instead asterisks are shown) out of a DTextEntry, but am constantly failing miserably. Is there an easy way to do this, or better, a pre-existing implementation?

local panel

panel = { }

panel.m_sPasswordChar = "*"
panel.m_sRealText = ""

AccessorFunc( panel, "m_sPasswordChar", "PasswordCharacter" )

function panel:GetRealText( )
	return self.m_sRealText

function panel:SetRealText( str )
	self.m_sRealText = str
	self:SetValue( string.rep( self:GetPasswordCharacter( ), #str ) )

function panel:OnTextChanged( )
	self:SetRealText( self:GetRealText( ) .. self:GetValue( ):sub( -1 ) )

function panel:UpdateConvarValue( )
	self:ConVarChanged( self:GetRealText( ) )

derma.DefineControl( "DTextEntryPassworded", "A textbox with password characters", panel, "DTextEntry" )

Use GetRealText to get the actual text.

Beat me to it, Kogitsune.


In the definition of the derma, he miss-spelled “Character”, you should fix that.

Thanks for spotting that, but it doesn’t actually affect the code :).

Edit: I got lost and bumped this, my bad