Authorize

Ok whats a script to make a window when the application starts up and make them type the code in 1 time?

Hey Slacker, Nitewing98 again. Not sure what you mean? You mean like to enter a registration code? Or an authorization for admin privilege to use some root/sudo function?

Where you have to regesture (at website or e-mail) then you type that code in and then the Application will beable to be used without it being used on a Trail.

hi slacker,

i hope I understood: You want your user to enter a registration code/password/serial number … and after entering this the first time your app shall no longer request this - correct?

Then you could save the code as a user default entry and check for this entry at program startup:


try
	set password  to (contents of default entry "pass" of user defaults)
on error -- no password entry exists ...
	-- ask for the password ...
	make new default entry at end of default entries of user defaults with properties {name:"pass", contents:thePassword}
end

yep you understood me correctly. But should i put that on the .nib option (as a startup) do i need to make a window or will it do it for me?

Sure - placing this in an ‘awake from nib’ handler should be ok.

No there is no window generated by the script yet. You can simply replace ‘-- ask for the password …’ with sth like:

set thePassword to (text returned of (display dialog "Please enter password:" default answer "" with hidden answer))

or you can programmatically generate a custom window/panel for this

or you can use an window/panel you made in InterfaceBuilder.

D.

YEY that part worked. but how do i make it so that applescript can check if the password is correct or not? i know how to make an error message script but i need to kno how to validate the password part. Any ideas?

Would it be possible to assign a variable to both the entered password and the correct one, and then compare them against each other like this:

set thePassword to (whatever the entered password was)
set theRealPassword to "Password"
if thePassword is theRealPassword
display dialog "Thanks for registering"
else
display dialog "The password you entered was incorrect. Please try again."
end if

The variable sargented is not defined.
That was a password that i madeup for the line: set thePassword to (sargented)

The password should be quoted, not in parentheses. Sorry about that.

How do you make

set thePassword to "sargented"
set theRealPassword to "sargented"
if thePassword is theRealPassword then
	display dialog "Thanks for registering"
else
	display dialog "The password you entered was incorrect. Please try again."
end if

into a display dialog? or a panel? cause when i try display dialog then it doesnt check to see if it’s correct.

I’m not quite clear on what you’re asking, but I’ll give it a shot anyway. The script already has a display dialog command; if you want it to perform some other action, replace that with whatever you want to do. To make it dependent upon whether or not the password is right, the command must remain within the “if” statement. The first part of the statement contains the script to execute if the password’s correct, and the second part contains the script to execute if it isn’t. To show a window in Xcode, just replace the “display dialog” with “show window” and the applescript name of the window in quotes.

the script that you gave me it just goes strait to Thanks for Registering. But it didnt ask for the password. and i was wondering what code i should use. or what way?

Oh, OK - here’s the code you need:


set thePassword to text returned of (display dialog "Please enter your password." default answer "")
set theRealPassword to "sargented"
if thePassword is theRealPassword then
   display dialog "Thanks for registering"
else
   display dialog "The password you entered was incorrect. Please try again."
end if

That should work.

Yey thanks guys for the help :slight_smile: :smiley: