Page 1 of 1
File creation.
Posted: Tue Jul 12, 2011 5:48 pm
by Kaubs
I am looking for a suggestion...a starting place more or less. When my app first starts it asks for a username and password....which are sent off to a server to authenticate...now when the application authenticates for the first time a file will be made containing the username and password essentially cached so that it can be used at a later time to authenticate with a different server when submitting a picture. The UN and PW will be the same on the second server but I don't want the user to have to input the info again. What I am looking for is what would be the best way to store this file so that it can be called and information pulled from it at a later time in the specialfolder or elsewhere? Could I have the iphone make something as simple as a text file or do I have to go with a mysql db? Just looking for a suggestion or other users experience with something similar so I can research and start writing the script in
Thanks,
Kaubs
Re: File creation.
Posted: Tue Jul 12, 2011 6:01 pm
by townsend
You certainly could put it in a text file, but there may be a better way. Chances are, once you get going you'll need to store other values besides the user name and password.
A while back I wrote a example app to demonstrate how to use the built in SQLite DB manager in LiveCode. There's a secondary Stack there, with this single function for saving and retrieving any values in a SQLite DB. It might be ideal for your needs. It's just one function, you can copy and paste into your app.
CRUD SQLite Example
Re: File creation.
Posted: Tue Jul 12, 2011 6:43 pm
by Klaus
Hi Kaubs,
Kaubs wrote:What I am looking for is what would be the best way to store this file so that it can be called and information pulled from it at a later time in the specialfolder or elsewhere?
I'm afraid you are thinking far too complicated!

Yes, you can simply store a simple textfile with the UN and PW in a "specialfolderpath"!
Kaubs wrote:Could I have the iphone make something as simple as a text file...
What makes you think you can't?
Out of my head:
Call this on openstack or whenever you need the Username and Password.
If the function returns EMPTY you need to lask for the username and password.
Code: Select all
function retrieveUNandPW
put specialfolderpath("documents") & "/your_file_name_here" into tFile
if there is a file tFile then
## File has been save here before:
return url("file:" & tFile)
else
## Not saved yet...
return empty
end if
end retrieveUNandPW
Save the data once the user entered them correctly:
Code: Select all
## 2 Parameter Username and Password
command saveUNandPW tUN, tPW
## Just save the stuff in a text file:
## First line = Username
## Second line = Password
put specialfolderpath("documents") & "/your_file_name_here" into tFile
put tUN & CR & tPW into url("file:" & tFile)
end saveUNandPW
You get the picture. A SQLite database seem a bit overkill in this case
Hope that helps!
Best
Klaus
Re: File creation.
Posted: Tue Jul 12, 2011 6:57 pm
by Kaubs
Thank you both! The SQL DB may come in handy at a later time...for the app I am creating right now the text file should be sufficient...I think I will start with that method and see what I can do.
Re: File creation.
Posted: Tue Jul 12, 2011 7:11 pm
by Kaubs
next question....lol. I have a simple login field, the user specifies the username and password. Would I use a function like rawkeyup to pull the data from those fields to my text file? Trying to put something together as if you literally had a field named username and a field named password with a button underneath called login.
Thanks again guys and Klaus you never sleep man!
Re: File creation.
Posted: Tue Jul 12, 2011 7:22 pm
by BvG
I would probably put the code into the "login" button. so when the user presses it, the app compares his entry with the stored data, and if it's a match, only then it would go to the next step.
Re: File creation.
Posted: Tue Jul 12, 2011 10:44 pm
by Kaubs
Ok, was trying to test the scripting and make sure it was working properly but something seems wrong....
Code: Select all
on mouseUp
send "saveUNandPW" to me in 0 milliseconds
end mouseUp
command saveUNandPW tUN, tPW
put specialfolderpath("documents") & "/test" into tFile
put tUN & CR & tPW into url("file:test.txt" & tFile)
if there is a file specialfolderpath("documents") & "/test" then
go to card 6
end if
end saveUNandPW
anything wrong there?
Re: File creation.
Posted: Tue Jul 12, 2011 11:21 pm
by Kaubs
Ok....after some testing this seemed to work. Is it correctly verifying that there is a file tho and if so its just an empty file right?
Code: Select all
on mouseUp
send "saveUNandPW" to me in 0 milliseconds
end mouseUp
command saveUNandPW tUN, tPW
put specialfolderpath("documents") & "/test" into tFile
put tUN & CR & tPW into url("file:" & tFile)
if there is a file tFile then
go to card 3
end if
end saveUNandPW
Re: File creation.
Posted: Wed Jul 13, 2011 1:00 pm
by Klaus
Hi Kaubs,
of course you need to supply the Username and the Password as the two parameters to my function!
Presumed this "mosueup" script is in the button "Login" or "OK" that the user clicks after he entered the username and pasword, right?
Code: Select all
on mouseUp
put fld "username" intotUN
put fld "password" int tPW
## The function need to knwo these two parameters!
## Otherwise you will find the strings tUN and tPW in that fiel!
saveUNandPW tUN, tPW
end mouseUp
command saveUNandPW tUN, tPW
## YEP! tFile IS already the correct filename!
put specialfolderpath("documents") & "/test" into tFile
put tUN & CR & tPW into url("file:" & tFile)
## NO idea what this is good for?????
if there is a file tFile then
go to card 3
end if
end saveUNandPW
Is it correctly verifying that there is a file tho and if so its just an empty file right?
Your "if there is a file..." does indeed check for the presence of that file, but I have no idea what its good for AFTER we wrote the file, so this check will always be positive!?
The script abvove will only write the username and password to that file!
If the file is already there, it will be overwritten!
This is not an empty file since we wrote the users name a pasword to it!
Best
Klaus
Re: File creation.
Posted: Wed Jul 13, 2011 5:40 pm
by Kaubs
Presumed this "mosueup" script is in the button "Login" or "OK" that the user clicks after he entered the username and pasword, right?
Correct!
I had used for testing to continue to the next card after the file was created. I couldn't find another way to verify that the file was in fact there.
The code
Code: Select all
on mouseUp
put fld "username" intotUN
put fld "password" int tPW
saveUNandPW tUN, tPW
end mouseUp
command saveUNandPW tUN, tPW
put specialfolderpath("documents") & "/test" into tFile
put tUN & CR & tPW into url("file:" & tFile)
go to card 3
end if
end saveUNandPW
Resides on my second card on the login button.
The stack itself will contain
Code: Select all
on openstack
put specialfolderpath("documents") & "/test" into tFile
if there is a file tFile then
go to card 3
end if
end openstack
Does this clear up what I am aiming for? If the user has specified correct credentials...which will be worked in with a server for authentication the user will not have to authenticate on subsequent visits to the app and it will just skip to card 3...Leaving the text file behind is so that I can collect the log in info later in the app to authenticate with another server without the users input.
Is the line "put specialfolderpath("documents") & "/test" into tFile" just creating a new file? If so...how on the stack would I verify the file exists and not replace it? How would changing directories for verification be handled?
Re: File creation.
Posted: Wed Jul 13, 2011 7:06 pm
by Kaubs
Ok...so this works. I verified the file contents using iPhone Explorer.
Card 2 contains 2 fields, one for username and one for password.
The login button contains this script
Code: Select all
on mouseUp
put fld "username" into tUN
put fld "password" into tPW
saveUNandPW tUN, tPW
end mouseUp
command saveUNandPW tUN, tPW
put specialfolderpath("documents") & "/text.txt" into tFile
put tUN & CR & tPW into url("file:" & tFile)
go to card 3
end saveUNandPW
The stack itself contains this script.
Code: Select all
on openstack
put specialfolderpath("documents") & "/text.txt" into tFile
if there is a file tFile then
go to card 3
end if
end openstack
Re: File creation.
Posted: Thu Jul 14, 2011 12:31 am
by Klaus
Hi Kaubs,
yes
Best
Klaus