my application has to use administrator privileges - I want to save the password in a text file…
As I want to be sure that the entered password is correct I want to compare the passwords - but this is not working:
set pass_file to ((path to me as Unicode text) & "Contents:Resources:pass.txt") as file specification
repeat
set pass_data to read pass_file as string
if pass_data is "0" then
repeat
set pass to text returned of (display dialog "Please enter your Code:" buttons {"Cancel", "Proceed"} default answer "")
set pass1 to text returned of (display dialog "Please enter your Code:" buttons {"Cancel", "Proceed"} default answer "")
if pass is equal to pass1 then exit repeat
end repeat
set pass_file to open for access pass_file with write permission
set eof of pass_file to 0
write (pass as string) to pass_file starting at eof
close access pass_file
end if
if pass_data is not "0" then exit repeat
end repeat
Does anyone has a clue why I am not leaving the Repeat with the password comparison?
thanks for the hint! I know its not secure, but I need the Password just for the Network Settings and not for the application itself - the Dialer will be protected by the SimCard Pin…
Thanks for your help - its is working perfect now!
the outer repeat block isn’t necessary.
You can add the is not “” check to the inner repeat block
set pass_file to ((path to me as Unicode text) & "Contents:Resources:pass.txt") as file specification
try
set pass_data to read pass_file -- will be read as string by default
on error
set pass_data to ""
end try
if pass_data is "" then
repeat
set pass to text returned of (display dialog "Please enter your Code:" buttons {"Cancel", "Proceed"} default answer "")
set pass1 to text returned of (display dialog "Please Reenter your Code:" buttons {"Cancel", "Proceed"} default answer "")
if pass is equal to pass1 and pass is not "" then exit repeat
end repeat
set pass_data to open for access pass_file with write permission
write (pass as string) to pass_data -- without specifying eof it starts at 0
close access pass_file
end if
I did some Brainstorming and found out, that I have to check wheter the password has changed…
try
set pass to read pass_file as string
on error
set pass to ""
end try
try
do shell script "ls ~root" password pass with administrator privileges
on error
set pass to ""
end try
if pass is "" ....
But there is no error when the password file is empty - means that the password box is opening instead of making the on error handler…