Page 1 of 1
Numeric Password…
Posted: Thu Aug 21, 2025 11:55 pm
by Piero
Code: Select all
Global StringGadgetFlags = #PB_String_Numeric ; set to 0 for normal password
#pwtooltip = "Password Input Field" ; use after creating StringGadget
Procedure ShowHidePass(StringGadget, activate = #True)
Protected x,y,w,h,s.s
x=GadgetX(StringGadget)
y=GadgetY(StringGadget)
w=GadgetWidth(StringGadget)
h=GadgetHeight(StringGadget)
s=GetGadgetText(StringGadget)
FreeGadget(StringGadget)
StringGadget(StringGadget,x,y,w,h,s,StringGadgetFlags)
GadgetToolTip(StringGadget,#pwtooltip)
If activate: SetActiveGadget(StringGadget) :EndIf
StringGadgetFlags ! #PB_String_Password
EndProcedure
OpenWindow(0, 0, 0, 250, 90, "Numeric Password")
StringGadget(0, 40, 20, 180, 20, "1234", StringGadgetFlags | #PB_String_Password)
GadgetToolTip(0, #pwtooltip )
CheckBoxGadget(1, 40, 55, 180, 25, "Show Password")
SetActiveGadget(0)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow : Break
Case #PB_Event_Gadget
If EventGadget() = 1
ShowHidePass(0)
EndIf
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
If EventType()=#PB_EventType_Focus And GadgetType(EventGadget())=#PB_GadgetType_String
SendMessage_(GadgetID(EventGadget()),#EM_SETSEL,0,-1)
EndIf
CompilerEndIf
EndSelect
ForEver
Re: Numeric Password…
Posted: Fri Aug 22, 2025 6:40 am
by idle
Thanks that's handy.
Re: Numeric Password…
Posted: Fri Aug 22, 2025 7:04 am
by Piero
idle wrote: Fri Aug 22, 2025 6:40 am
Thanks that's handy.
YW
PS: I just added a "fix" for windoze

Re: Numeric Password…
Posted: Fri Aug 22, 2025 2:57 pm
by Axolotl
Thanks for sharing.
BTW: On Window I prefer another 'fix' called API constant #EM_SETPASSWORDCHAR
Code: Select all
Global StringGadgetFlags = #PB_String_Numeric ; set to 0 for normal password
#pwtooltip = "Password Input Field" ; use after creating StringGadget
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
Procedure DisableStringGadgetPassword(Gadget, State)
If State
SendMessage_(GadgetID(Gadget), #EM_SETPASSWORDCHAR, 0, 0)
Else
SendMessage_(GadgetID(Gadget), #EM_SETPASSWORDCHAR, '●', 0)
EndIf
EndProcedure
CompilerElse ; #PB_Compiler_OS = #ALL_THE_OTHERS
Procedure ShowHidePass(StringGadget, activate = #True)
Protected x,y,w,h,s.s
x=GadgetX(StringGadget)
y=GadgetY(StringGadget)
w=GadgetWidth(StringGadget)
h=GadgetHeight(StringGadget)
s=GetGadgetText(StringGadget)
FreeGadget(StringGadget)
StringGadget(StringGadget,x,y,w,h,s,StringGadgetFlags)
GadgetToolTip(StringGadget,#pwtooltip)
If activate: SetActiveGadget(StringGadget) :EndIf
StringGadgetFlags ! #PB_String_Password
EndProcedure
CompilerEndIf
OpenWindow(0, 0, 0, 250, 90, "Numeric Password")
StringGadget(0, 40, 20, 180, 20, "1234", StringGadgetFlags | #PB_String_Password) ; #PB_String_Numeric
GadgetToolTip(0, #pwtooltip )
CheckBoxGadget(1, 40, 55, 180, 25, "Show Password")
SetActiveGadget(0)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow : Break
Case #PB_Event_Gadget
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
If EventGadget() = 1
DisableStringGadgetPassword(0, GetGadgetState(1))
SetActiveGadget(0)
EndIf
CompilerElse
If EventGadget() = 1
ShowHidePass(0)
EndIf
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
If EventType()=#PB_EventType_Focus And GadgetType(EventGadget())=#PB_GadgetType_String
SendMessage_(GadgetID(EventGadget()),#EM_SETSEL,0,-1)
EndIf
CompilerEndIf
CompilerEndIf
EndSelect
ForEver
Re: Numeric Password…
Posted: Fri Aug 22, 2025 4:29 pm
by ebs
@Axolotl,
Thank you! Your tip about about #EM_SETPASSWORDCHAR is exactly what I need.
One question - do you know how I can do this in an ancient ASCII (not UNICODE) executable?
I would have thought that passing the correct value as wParam should be all that's required, but I can't get it to work,.
I read that the black dot UNICODE character is entered by typing ALT+25CF, so I tried $25CF and 9679, but neither one worked.
Is there a way to create the proper value in an ASCII executable? Maybe just encode the password string as UNICODE?
Re: Numeric Password…
Posted: Fri Aug 22, 2025 4:53 pm
by Axolotl
Well, my first (lucky) guess is to use '*' instead. Because the asterisk is a valid ascii char.
Second idea: try to use the #EM_GETPASSWORDCHAR to find out the using char. (should be the result or zero if in not password mode)
Re: Numeric Password…
Posted: Fri Aug 22, 2025 5:06 pm
by ebs
Thanks for your fast reply.
I did try #EM_GETPASSWORDCHAR and guess what it returns? '*'
I did find a way to cheat by changing the font to Wingdings and using one of the black dot characters in that font, then switching back to the default font when showing the actual password characters. It (the code) isn't pretty, but it works!
Re: Numeric Password…
Posted: Fri Aug 22, 2025 5:20 pm
by threedslider
Thanks @Piero for sharing your code
Mine is instead of numeric i put character

, here the code :
Code: Select all
Global StringGadgetFlags = #PB_String ; set to 0 for normal password
#pwtooltip = "Password Input Field" ; use after creating StringGadget
Procedure ShowHidePass(StringGadget, activate = #True)
Protected x,y,w,h,s.s
x=GadgetX(StringGadget)
y=GadgetY(StringGadget)
w=GadgetWidth(StringGadget)
h=GadgetHeight(StringGadget)
s=GetGadgetText(StringGadget)
FreeGadget(StringGadget)
StringGadget(StringGadget,x,y,w,h,s,StringGadgetFlags)
GadgetToolTip(StringGadget,#pwtooltip)
If activate: SetActiveGadget(StringGadget) :EndIf
StringGadgetFlags ! #PB_String_Password
EndProcedure
OpenWindow(0, 0, 0, 250, 90, "Character Password")
StringGadget(0, 40, 20, 180, 20, "hello", StringGadgetFlags | #PB_String_Password)
GadgetToolTip(0, #pwtooltip )
CheckBoxGadget(1, 40, 55, 180, 25, "Show Password")
SetActiveGadget(0)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow : Break
Case #PB_Event_Gadget
If EventGadget() = 1
ShowHidePass(0)
EndIf
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
If EventType()=#PB_EventType_Focus And GadgetType(EventGadget())=#PB_GadgetType_String
SendMessage_(GadgetID(EventGadget()),#EM_SETSEL,0,-1)
EndIf
CompilerEndIf
EndSelect
ForEver
Enjoy and happy coding !
Re: Numeric Password…
Posted: Fri Aug 22, 2025 8:54 pm
by Piero
1) You windoze ppl always complicate simple PB multiplatform solutions with your api stuff
2) I must admit that """#EM_SETPASSWORDCHAR""" is the way it should work on all platforms
3) You must admit that your StringGadget text doesn't get selected on focus
Edit: replaced the colloquial "sh*t" with the synonymous "stuff" to avoid """misinterpretations"""
Re: Numeric Password…
Posted: Fri Aug 22, 2025 11:32 pm
by Kiffi
Piero wrote: Fri Aug 22, 2025 8:54 pm1) You windoze ppl always complicate simple PB multiplatform solutions with your api sh*

Please avoid disrespectful wording like that. Let’s keep the discussion polite and technical.
Re: Numeric Password…
Posted: Sat Aug 23, 2025 12:17 am
by Piero
Kiffi wrote: Fri Aug 22, 2025 11:32 pm
Piero wrote: Fri Aug 22, 2025 8:54 pm1) You windoze ppl always complicate simple PB multiplatform solutions with your api sh*

Please avoid disrespectful wording like that. Let’s keep the discussion polite and technical.
Hey Kiffi, I'm very surprised to hear you "took my words as disrespectful"
I also use win, but that's not the point: I'm not the only one that thinks that (
viewtopic.php?p=644313#p644313 )
Anyway I have no problems with it; I just think the overwhelming majority here (win users) should LEARN not to "take as granted" that we all use windows (I dunno how to explain myself better: it's also for their own benefit…)
Anyway, to be sincere, I feel very uncomfortable when using win (even more when using a cell phone…)
Seems I used Mac too much
