flamendless / Slab

An immediate mode GUI for the Love2D framework.
MIT License
286 stars 25 forks source link

Allow parsing of `Input` strings for passwords #125

Closed pakeke-constructor closed 1 year ago

pakeke-constructor commented 2 years ago

Currently, if you type in an Input box, the string is shown, no matter what. This is bad for stuff like passwords!

A good feature to have would be to add some options to obscure text.

Proposed example:

local str = "my password"
if Slab.Input("id", {Text = str, Password = true, PasswordChar = "*"}) then
end
--will display  ***********
flamendless commented 2 years ago

slab_pw

Here's a WIP for now that's usable :) Will improve soon after refactorization from megagrump

local str = "sample pw"
local pw_char = "*"
local show_pw = true

function love.update(dt)
    Slab.Update(dt)
    Slab.BeginWindow("sample", {Title = "Sample"})
    Slab.Text("Password")
    Slab.SameLine()
    if Slab.Input("pw", {Text = str, IsPassword = show_pw, PasswordChar = pw_char}) then
        str = Slab.GetInputText()
    end

    Slab.Text("Password Char Mask")
    Slab.SameLine()
    if Slab.Input("pw_char", {Text = pw_char}) then
        pw_char = Slab.GetInputText()
    end
    if Slab.CheckBox(show_pw, "show pw") then
        show_pw = not show_pw
    end
        Slab.EndWindow()
end

Wiki is updated

pakeke-constructor commented 2 years ago

Awesome!! This looks great- I’m really appreciative of the fast response, and all the effort you guys put in to this library. Feel free to close this whenever you are happy with it

flamendless commented 2 years ago

Not yet complete though. I still have to mask the text when the user selected it and is typing on it

flamendless commented 1 year ago

I still have to mask the text when the user selected it and is typing on it

Is implemented for v1.0.0 (6ad832659dabf744212ad3baafddeb6cc4f14b96)