Imgui: Password field

Created on 29 May 2015  Â·  12Comments  Â·  Source: ocornut/imgui

Is it possible to make ImGui::InputText draw * or # instead of actual text, i want to make a password edit in my application? Here's the video of my current use of ImGUI http://www.youtube.com/watch?v=KVj2G10PaDc

inputtext

Most helpful comment

This was the first page that came up when I googled and I almost implemented the proposed solutions. Luckily, I found through more searching that the password functionality had already been put in place (thanks to whoever it was). A password input text can be placed as:

ImGui::InputText("Password",passBuffer,IM_ARRAYSIZE(passBuffer),ImGuiInputTextFlags_Password);

I'm just leaving this here in case others stumble on this page like I did.

All 12 comments

That's possible I suppose, given some work. It would also have to disable copying to clipboard possibly.

If you need it quickly, a possible hack/workaround would be to create a separate font and only load the * glyph in it, then call font->SetFallbackChar('*') during init, then use that font for the text field with PushFont, InputText, PopFont. It will still be possible to copy the data to clipboard however.

Thank you for great idea, i will try that.

Your idea worked, i loaded 0x002a range for *, you can put this in low priority

Cool. I gave it a quick attempt but it's not that easy since every code path called by InputText need to take account of it. If using a monospaced font it'd be trivial but ImGui support different fonts so I can't assume monospaced. I don't think it is worth doing the change right now if the workaround is functional :)

Depending on what sort of security you want you may need:

  • to disable clipboard by setting io.SetClipboardTextFn to NULL.
  • to make sure that logging via the Log** api is not possible.

I could easily add a flag to disable clipboard and logging but NOT swap the font (that's harder, not worth it right now).

PS: for Cyrillic which Unicode range do you actually need ?
0400-04FF , 0500–052F, 2DE0–2DFF, A640–A69F ? is that too much, or too little ?
I could add a new GetGlyphRanges** function.

i use this http://jrgraphix.net/r/Unicode/0400-04FF this site has very nice list of ranges

i think it would be better if you just implement InputPassword when you have the time
in that function you pass classic params and replace_char * or # or a function, so user can decide what to replace for display.

here's snippet of what i used

if (!Password.Empty() && Password != UserEPass)
    {   
        ImGui::PushFont(pass_font);
        ImGui::InputText("", (char*)UserEPass.c_str(), CSTR_CACHE);
        ImGui::PopFont();

        ImGui::SameLine();
        ImGui::Text(PasswordTitle.c_str());

        if (Password != UserEPass)
        {
            ImGui::End();
            return;
        }
    }
}

and

//load * font
    static const ImWchar ranges[] =
    {
        0x002a, 0x002b, // Basic Latin + Latin Supplement
        0,
    };
    pass_font = ImGui::GetIO().Fonts->AddFontFromFileTTF("data/IMFonts/DroidSans.ttf", 16.0f, ranges);
    pass_font->SetFallbackChar('*');

here's the video http://www.youtube.com/watch?v=9jctfoaqig8
there was one more feauture i would really want in im, it's ability to pass wchar_t into functions[that function will convert it to UTF8 automaticly]. Our framework has everything in Unicode, so when i try to attach that with GUI i have to convert them myself with this header library http://utfcpp.sourceforge.net/

Should work! PS: You should pass an id to InputText like "##password" (anything after ## is not displayed) else it'll collision with other widgets.

I've updated it, thanks for suggestion. So what do you think about ability to pass wchar_t*? I wrote it in the post above.

Sorry missed on the above. It'd be a little too much work to convert the data, keep the code clean and stay efficient. But you can create your new functions to help yourself ?

namespace ImGui
{
  bool Button(wchar_t*);
};
bool ImGui::Button(wchar_t label)
{
   // convert ...
   return ImGui::Button(utf8_label);
}

etc.

This was the first page that came up when I googled and I almost implemented the proposed solutions. Luckily, I found through more searching that the password functionality had already been put in place (thanks to whoever it was). A password input text can be placed as:

ImGui::InputText("Password",passBuffer,IM_ARRAYSIZE(passBuffer),ImGuiInputTextFlags_Password);

I'm just leaving this here in case others stumble on this page like I did.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

the-lay picture the-lay  Â·  3Comments

SlNPacifist picture SlNPacifist  Â·  3Comments

DarkLinux picture DarkLinux  Â·  3Comments

mkanakis picture mkanakis  Â·  3Comments

ocornut picture ocornut  Â·  3Comments