Jump to content

Script password protection help


Recommended Posts

Hi all,

I have another newb question for you all :)

I'm simply trying to password protect a script so it isn't run by accident. I've gotten this far using the help file and some posts here:

$pass = InputBox( "Password", "Please enter password", "", "*", 190, 115)
If @Error Then Exit
If $pass = "@reboot" Then
MsgBox( 1, "Accepted", "Password accepted!", 30)
Else
    MsgBox( 1, "Rejected!", "Incorrect Password", 5)
EndIf

What I'm looking for is 1) have the rest of the script not start and exit if at anytime "Cancel" is pressed and 2) if the password is incorrect have it loop back and ask for it again, and obviously 3) have the rest of the script start after a successful password and clicking "OK".

Any help would be appreciated.

Edited by jayshomp
Link to comment
Share on other sites

Global $Password="password";put your password here...
$pass = InputBox( "Password", "Please enter password", "", "*", 190, 115)
If @Error Then Exit
If $pass = $Password Then
MsgBox( 1, "Accepted", "Password accepted!", 30)
Else
    MsgBox( 1, "Rejected!", "Incorrect Password", 5)
EndIf

;Rest of script goes here....

Edited by Swift
Link to comment
Share on other sites

Global $Password="password";put your password here...
$pass = InputBox( "Password", "Please enter password", "", "*", 190, 115)
If @Error Then Exit
If $pass = $Password Then
MsgBox( 1, "Accepted", "Password accepted!", 30)
Else
    MsgBox( 1, "Rejected!", "Incorrect Password", 5)
EndIf

;Rest of script goes here....
Thank you Swift but I'm still getting the same problem. The script still starts if clicking OK or Cancel in the Rejected box after an incorrect password is entered :)
Link to comment
Share on other sites

While 1
Global $pass = InputBox( "Password", "Please enter password", "", "*", 190, 115)
If @error Then Exit
If $pass = "@reboot" Then ExitLoop
 MsgBox( 1, "Rejected!", "Incorrect Password", 5)
WEnd

MsgBox( 1, "Accepted", "Password accepted!", 30)

;Script goes here

Link to comment
Share on other sites

While 1
Global $pass = InputBox( "Password", "Please enter password", "", "*", 190, 115)
If @error Then Exit
If $pass = "@reboot" Then ExitLoop
 MsgBox( 1, "Rejected!", "Incorrect Password", 5)
WEnd

MsgBox( 1, "Accepted", "Password accepted!", 30)

;Script goes here
Thank you Chip, that's just about perfect. The last thing I need is for the script to exit if Cancel is pressed in the Accepted box. I thought "If @Error Then Exit" would work but apparently not :)

The rest is exactly what I was looking for though, thank you again!

Link to comment
Share on other sites

Thank you Chip, that's just about perfect. The last thing I need is for the script to exit if Cancel is pressed in the Accepted box. I thought "If @Error Then Exit" would work but apparently not :)

The rest is exactly what I was looking for though, thank you again!

Nevermind I found it finally: If @error == 0 Then Exit

Thanks again!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...