[Function] Password prompt

Post your working scripts, libraries and tools for AHK v1.1 and older
Shadowpheonix
Posts: 1259
Joined: 16 Apr 2015, 09:41

[Function] Password prompt

04 May 2016, 09:55

Code: Select all

; Password request dialog with customizable window title & prompt text, and a masking toggle.
GetPassword(PassText:="What is your password?", PassTitle:="Password Prompt", UnHide:="0")
{
	If UnHide != 0
		UnHide = 1
	Global MyPassword
	Gui, MPP:New, +HwndMPPGuiHWND
	Gui, +LastFound
	Gui, Add, Text, XM+5 R1 w200, %PassText%
	If Unhide != 0
		Gui, Add, Edit, R1 vMyPassword w150
	Else
		Gui, Add, Edit, Password R1 vMyPassword w150
	Gui, Add, Checkbox, gMPPShowPass h15 w15 Xp+155 YP+3,
	Gui, Add, Button, Default R1 W50 XM, &OK
	Gui, Add, Button, R1 W50 XP+130, &Cancel
	If Unhide = 0
		Gosub MPPShowPass
	Gui, MPP:Show, W200, %PassTitle%
	Gui MPP:+AlwaysOnTop -SysMenu
	WinWaitClose, AHK_id %MPPGuiHWND%
	Return MyPassword
; End main GetPassword function.

; Begin GetPassword GUI sub-routines.
	MPPGuiEscape:
	MPPGuiClose:
	MPPButtonCancel:
	Gui, MPP:Destroy
	MyPassword :=
	Return

	MPPButtonOK:
	Gui, MPP:Submit
	Gui, MPP:Destroy
	Return

	MPPShowPass:
	Gui, MPP:Submit, NoHide
	GuiControlGet, RadioState, , Button1
	If RadioState = 1
	{
		GuiControl, MPP: -Password, Edit1
	}
	Else
	{
		GuiControl, MPP: +Password, Edit1
	}
	GuiControl, MPP:, Edit1, %MyPassword%
	GuiControl, MPP:Focus, Edit1
	ControlSend, Edit1, {End}
	Return
; End GetPassword GUI sub-routines.
}
Spitzi
Posts: 313
Joined: 24 Feb 2022, 03:45

Re: [Function] Password prompt

24 Feb 2022, 04:02

Thanks for that!
As a Feedback: If the PassText is too long, it won't be fully displayed.
carno
Posts: 265
Joined: 20 Jun 2014, 16:48

Re: [Function] Password prompt

14 Mar 2022, 19:56

Thanks for this script. I tested for a 100-char long password and it passed the test with flying colors!

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: EIijah_2cm and 78 guests