|
Post by Mark Dunham on Apr 11, 2019 13:28:40 GMT -5
I made a sample program that requires you to enter the correct password before using the actual program. This is just a demo so I made it as simple as possible I am planning to implement it into a future project. I might add user login into it as well I am still thinking on it. My sample program is based off of the following link.
'PASSWORD PROTECTED PROGRAM
nomainwin
Password$ = "Knock"
WindowWidth = 275 WindowHeight = 150
'TEXTBOX USING STYLEBITS FOR PASSWORD SETTINGS stylebits #Pass.pw, _ES_PASSWORD, _ES_AUTOVSCROLL or _ES_MULTILINE, 0, 0 textbox #Pass.pw, 10, 40, 250, 25 button #Pass.Submit, "Submit", [Submit], UL, 110, 75
'STYLEBITS TO DRESS UP THE POPUP WINDOW stylebits #Pass, _WS_SYSMENU, _WS_POPUP, 0,0 open "Password" for window_popup as #Pass
wait
[Submit] #Pass.pw, "!contents? pass$" if pass$ = Password$ then close #Pass goto [Main] end if wait
'MAIN WINDOW OF OUR PROGRAM ONCE THE CORRECT PASSWORD HAS BEEN ENTERED [Main] WindowWidth = 640 WindowHeight = 480 open "Main Window" for window as #Main
wait
|
|
|
Post by Rod on Apr 11, 2019 13:35:55 GMT -5
Cool, needs more feedback and assistance if password is not right. Sullen silence is never a good ploy.
|
|
|
Post by Mark Dunham on Apr 11, 2019 13:38:37 GMT -5
Cool, needs more feedback and assistance if password is not right. Sullen silence is never a good ploy. Rod, you are absolutely correct. I added a notice if it's incorrect.
'PASSWORD PROTECTED PROGRAM
nomainwin
Password$ = "Knock"
WindowWidth = 275 WindowHeight = 150
'TEXTBOX USING STYLEBITS FOR PASSWORD SETTINGS stylebits #Pass.pw, _ES_PASSWORD, _ES_AUTOVSCROLL or _ES_MULTILINE, 0, 0 textbox #Pass.pw, 10, 40, 250, 25 button #Pass.Submit, "Submit", [Submit], UL, 110, 75
'STYLEBITS TO DRESS UP THE POPUP WINDOW stylebits #Pass, _WS_SYSMENU, _WS_POPUP, 0,0 open "Password" for window_popup as #Pass
wait
[Submit] #Pass.pw, "!contents? pass$" if pass$ = Password$ then close #Pass goto [Main] else notice "The password you entered is incorrect! Please try again." end if wait
'MAIN WINDOW OF OUR PROGRAM ONCE THE CORRECT PASSWORD HAS BEEN ENTERED [Main] WindowWidth = 640 WindowHeight = 480 open "Main Window" for window as #Main
wait
|
|
|
Post by alincon on Apr 11, 2019 14:06:43 GMT -5
I think you should abort the login after, say, three tries. Also, set focus to the text box so the user does not have to click on it to start typing.
r.m.
|
|
|
Post by Mark Dunham on Apr 11, 2019 14:16:55 GMT -5
I think you should abort the login after, say, three tries. Also, set focus to the text box so the user does not have to click on it to start typing. r.m. Following your suggested improvements I have implemented them into my example. This is what makes this community great. Thanks for the input.
'PASSWORD PROTECTED PROGRAM
nomainwin
Password$ = "Knock" IncorrectTries = 0
WindowWidth = 275 WindowHeight = 150
'TEXTBOX USING STYLEBITS FOR PASSWORD SETTINGS stylebits #Pass.pw, _ES_PASSWORD, _ES_AUTOVSCROLL or _ES_MULTILINE, 0, 0 textbox #Pass.pw, 10, 40, 250, 25 button #Pass.Submit, "Submit", [Submit], UL, 110, 75
'STYLEBITS TO DRESS UP THE POPUP WINDOW stylebits #Pass, _WS_SYSMENU, _WS_POPUP, 0,0 open "Password" for window_popup as #Pass #Pass.pw, "!setfocus"
wait
[Submit] #Pass.pw, "!contents? pass$" if pass$ = Password$ then close #Pass goto [Main] else notice "The password you entered is incorrect! Please try again." IncorrectTries = IncorrectTries + 1 if IncorrectTries = 3 then notice "Too many failed attempts! Program will Exit." close #Pass end if end if wait
'MAIN WINDOW OF OUR PROGRAM ONCE THE CORRECT PASSWORD HAS BEEN ENTERED [Main] WindowWidth = 640 WindowHeight = 480 open "Main Window" for window as #Main
wait
|
|
|
Post by metro on Apr 11, 2019 18:36:13 GMT -5
I hope you don't mind.... my 2 cents worth I like the ability to press enter when the password is complete so i would make the window a dialog and rename the button
button #Pass.Default, "Submit", [Submit], UL, 110, 75 of course the user could press <tab> then enter the only "con" to my approach is if the user presses <esc> the dialog will close
|
|
|
Post by Mark Dunham on Apr 11, 2019 18:55:25 GMT -5
I hope you don't mind.... my 2 cents worth I like the ability to press enter when the password is complete so i would make the window a dialog and rename the button button #Pass.Default, "Submit", [Submit], UL, 110, 75 of course the user could press <tab> then enter the only "con" to my approach is if the user presses <esc> the dialog will close I will take any feedback I never mind it all gets me thinking and just helps me become a better programmer.
|
|
|
Post by alincon on Apr 11, 2019 20:42:19 GMT -5
What happens if the user clicks the window close button? There's a stylebits to remove the box, but I can't find it right now.
r.m.
|
|
|
Post by Mark Dunham on Apr 11, 2019 20:55:29 GMT -5
What happens if the user clicks the window close button? There's a stylebits to remove the box, but I can't find it right now. r.m. If they click the "X" to close the password window the program exits.
|
|
|
Post by metro on Apr 11, 2019 20:58:07 GMT -5
I like to not have to clear the password if I make a mistake so maybe add in #Pass.pw, "!selectall"
[b] [Submit] #Pass.pw, "!contents? pass$" if pass$ = Password$ then close #Pass goto [Main] else notice "The password you entered is incorrect! Please try again." IncorrectTries = IncorrectTries + 1 #Pass.pw, "!selectall" if IncorrectTries = 3 then notice "Too many failed attempts! Program will Exit." close #Pass end if end if wait [/b]
|
|
|
Post by Mark Dunham on Apr 11, 2019 21:38:36 GMT -5
I like to not have to clear the password if I make a mistake so maybe add in #Pass.pw, "!selectall" [b] [Submit] #Pass.pw, "!contents? pass$" if pass$ = Password$ then close #Pass goto [Main] else notice "The password you entered is incorrect! Please try again." IncorrectTries = IncorrectTries + 1 #Pass.pw, "!selectall" if IncorrectTries = 3 then notice "Too many failed attempts! Program will Exit." close #Pass end if end if wait [/b] Great suggestion I will add it in thank you for all the advice.
|
|
|
Post by tsh73 on Apr 12, 2019 3:54:32 GMT -5
You can move notice "try again" down, like this. So you not get
and then instantly
else IncorrectTries = IncorrectTries + 1 if IncorrectTries = 3 then notice "Too many failed attempts! Program will Exit." close #Pass end if notice "The password you entered is incorrect! Please try again." end if
|
|
|
Post by Mark Dunham on Apr 12, 2019 7:30:49 GMT -5
You can move notice "try again" down, like this. So you not get and then instantly else IncorrectTries = IncorrectTries + 1 if IncorrectTries = 3 then notice "Too many failed attempts! Program will Exit." close #Pass end if notice "The password you entered is incorrect! Please try again." end if
tsh73 I tried your example of moving the notice for too many failed attempts down. When I do that when you get the 3rd failed attempt as the programming is closing you still get one more failed password notice. metro I changed the window to a dialog window and enter still does not work for submit I believe it is because the textbox has focus and not the dialog window.
'PASSWORD PROTECTED PROGRAM
nomainwin
Password$ = "Knock" IncorrectTries = 0
WindowWidth = 285 WindowHeight = 175
'TEXTBOX USING STYLEBITS FOR PASSWORD SETTINGS stylebits #Pass.pw, _ES_PASSWORD, _ES_AUTOVSCROLL or _ES_MULTILINE, 0, 0 textbox #Pass.pw, 10, 40, 250, 25 button #Pass.Submit, "Submit", [Submit], UL, 110, 75
'STYLEBITS TO DRESS UP THE POPUP WINDOW stylebits #Pass, _WS_SYSMENU, _WS_POPUP, 0,0 open "Password" for dialog_popup as #Pass #Pass.pw, "!setfocus"
wait
[Submit] #Pass.pw, "!contents? pass$" if pass$ = Password$ then close #Pass goto [Main] else notice "The password you entered is incorrect! Please try again." IncorrectTries = IncorrectTries + 1 #Pass.pw, "!selectall" if IncorrectTries = 3 then notice "Too many failed attempts! Program will Exit." close #Pass end if end if wait
'MAIN WINDOW OF OUR PROGRAM ONCE THE CORRECT PASSWORD HAS BEEN ENTERED [Main] WindowWidth = 640 WindowHeight = 480 open "Main Window" for window as #Main
wait
|
|
|
Post by Mark Dunham on Apr 12, 2019 7:33:45 GMT -5
metro I just noticed I forgot to change the submit button to .Default now enter works . Is there any documentation on "Default" it is the first time I have seen it with a button. 'PASSWORD PROTECTED PROGRAM
nomainwin
Password$ = "Knock" IncorrectTries = 0
WindowWidth = 285 WindowHeight = 175
'TEXTBOX USING STYLEBITS FOR PASSWORD SETTINGS stylebits #Pass.pw, _ES_PASSWORD, _ES_AUTOVSCROLL or _ES_MULTILINE, 0, 0 textbox #Pass.pw, 10, 40, 250, 25 button #Pass.Default, "Submit", [Submit], UL, 110, 75
'STYLEBITS TO DRESS UP THE POPUP WINDOW stylebits #Pass, _WS_SYSMENU, _WS_POPUP, 0,0 open "Password" for dialog_popup as #Pass #Pass.pw, "!setfocus"
wait
[Submit] #Pass.pw, "!contents? pass$" if pass$ = Password$ then close #Pass goto [Main] else notice "The password you entered is incorrect! Please try again." IncorrectTries = IncorrectTries + 1 #Pass.pw, "!selectall" if IncorrectTries = 3 then notice "Too many failed attempts! Program will Exit." close #Pass end if end if wait
'MAIN WINDOW OF OUR PROGRAM ONCE THE CORRECT PASSWORD HAS BEEN ENTERED [Main] WindowWidth = 640 WindowHeight = 480 open "Main Window" for window as #Main
wait
|
|
|
Post by metro on Apr 12, 2019 7:55:43 GMT -5
Some reading here.well down the page and here
|
|