Page 1 of 2
how do I encrypt a field?
Posted: Thu Jan 20, 2011 3:06 pm
by krawson1
Hello Forum,
I'm an amateur programmer who uses Livecode for educational/research purposes. I have a script question that I hope someone out there can help me with. I know that in pop-up windows you can tell Livecode to encrypt the information that the user sees -- for example:
ask password clear "What is your ID #?"
Does anyone know how to have Livecode encrypt the content entered into a field?
Re: how do I encrypt a field?
Posted: Thu Jan 20, 2011 4:17 pm
by FourthWorld
I don't know the specific encryption method the engine uses for "ask password", but if you need to encrypt data you have at least two options:
For really-stupid-but-somewhat-useful-for-basic-tasks encryption, the pack and unpack functions here provide very rudimentary encryption that may be suitable if your security concerns are minimal:
http://livecodejournal.com/tutorials/ha ... s-005.html
Pack and unpack compress data before encryption and then pass it through base64Encode/decode, making them convenient for network transfer.
For industrial-strength encryption see the Dictionary entries for Rev's encrypt and decrypt commands, which offer options for Blowfish and other very powerful encryption methods. See also the cipherNames function which returns a list of available encryption methods.
If network transfer is desired you can easily pass the values altered by encrypt and decrypt through bas64encode/decode by call them in a simple accessor function, so while pack and unpack are small and convenient if you need truly strong encryption you may want to consider encrypt and decrypt.
Re: how do I encrypt a field?
Posted: Thu Jan 20, 2011 5:31 pm
by dunbarx
Do you simply want to hide the entered data? Sort of like the bullets that appear in a field so that a casual onlooker cannot read your password as you type? There are several cute ways to effect this.
Or is Richard's reply about full blown file encryption more pertinent?
Write back if you need to.
Craig Newman
Re: how do I encrypt a field?
Posted: Thu Jan 20, 2011 5:58 pm
by krawson1
Yes, that's right, I just need to hide the data that our research participants type into the field with bullets or asterisks (long story short, we'll be asking people to type in the spelling of words but we don't want them to be able to see what they've typed, to prevent them from deciding if a spelling "looks right"). Thanks for any advice you have!
Re: how do I encrypt a field?
Posted: Thu Jan 20, 2011 8:45 pm
by dunbarx
Hi.
This should get you started. Put these three handlers into your field script:
Code: Select all
on keydown var
set the currentData of me to the currentData of me & var
put "•" after me
end keydown
on deleteKey
set the currentData of me to char 1 to -2 of the currentData of me
delete the last char of me
end deleteKey
on backspaceKey
set the currentData of me to char 1 to -2 of the currentData of me
delete the last char of me
end backspaceKey
Not severely tested, but seems to work OK. I am using a custom property of the field to hold your actual data, and just filling in the field itself with bullets. If you read the scripts you should be able to see how this very simple thing works, and should be able to modify it so that you can display, or send along, the actual data if you need to.
Craig Newman
Re: how do I encrypt a field?
Posted: Thu Jan 20, 2011 11:37 pm
by krawson1
This is incredibly helpful, thank you so much for your prompt replies and advice!!
Cheers,
Katherine
Re: how do I encrypt a field?
Posted: Thu Jan 27, 2011 3:34 pm
by richh
dunbarx wrote:Hi.
This should get you started. Put these three handlers into your field script:
Code: Select all
on keydown var
set the currentData of me to the currentData of me & var
put "•" after me
end keydown
on deleteKey
set the currentData of me to char 1 to -2 of the currentData of me
delete the last char of me
end deleteKey
on backspaceKey
set the currentData of me to char 1 to -2 of the currentData of me
delete the last char of me
end backspaceKey
Not severely tested, but seems to work OK. I am using a custom property of the field to hold your actual data, and just filling in the field itself with bullets. If you read the scripts you should be able to see how this very simple thing works, and should be able to modify it so that you can display, or send along, the actual data if you need to.
Craig Newman
Thank you Craig...
quick question, if I wanted to pull the information from the currentData custom property, how would I interact with it from another object?
would I need to make currentData a global variable?
Re: how do I encrypt a field?
Posted: Thu Jan 27, 2011 4:18 pm
by Klaus
Hi Rich,
you can address a CP directly:
...
put the CurrentData of btn "the one with the CP" into whatever
## or whatever object holds this CP
## or even from other cards and/or stacks:
## put the CurrentData of btn "the one with the CP" of cd "XY" of stack "Z" into whatever
...
Best
Klaus
Re: how do I encrypt a field?
Posted: Thu Jan 27, 2011 6:26 pm
by dunbarx
"CurrentData" is the custom property that was created in the various handlers in the field script. It was created on the fly by setting it to the value of the key pressed. It was updated in a similar fashion. Custom properties may be manipulated in all the usual ways that any other property is. One may set them and get them.
Since the actual data is "in" the custom property of the field, Simply:
get the currentData of fld "yourField"
Properties are not containers, so you cannot "put" something into a property.
Re: how do I encrypt a field?
Posted: Thu Jan 27, 2011 7:18 pm
by richh
Thank you Klaus and dunbarx....
I tried the following in a button:
Code: Select all
on mouseUp
answer info currentData of Field 1
end mouseUp
but comes back with currentData... not the content of current data.
EDIT:
actually.. I get an error after:
Code: Select all
button "Button": execution error at line 2 (Handler: can't find handler) near "of", char 16
Re: how do I encrypt a field?
Posted: Thu Jan 27, 2011 7:46 pm
by Klaus
Hi Rich,
clean your glasses, please!
As we already unmistakably wrote in our postings:
...
answer THE currentData of fld 1
...
Best
Klaus
Re: how do I encrypt a field?
Posted: Thu Jan 27, 2011 7:55 pm
by richh
hehe.. consider glasses cleaned
it was odd though, the moment I closed out of LiveCode and relaunched.. it started to work again..
this works:
Code: Select all
put the currentData of Field "passwordField" into tData
answer info the currentData of Field "passwordField"
thanks again

// Still getting used to the syntax

Re: how do I encrypt a field?
Posted: Thu Jan 27, 2011 8:38 pm
by dunbarx
Klaus.
There is another parameter that can be associated with the answer command. It is the icontype, and "information" (and, I guess, "info) is allowed. The "the" is optional when calling a property. Both these work:
answer the testProperty of yourObject
answer testProperty of yourObject
HC also allowed this flexibility.
Re: how do I encrypt a field?
Posted: Thu Jan 27, 2011 9:00 pm
by dunbarx
Rich.
I would always be careful with syntax. Errant words that seem to read better usually will break something, however forgiving this language is.
So "info" as a valid synonym for "information" (as per the examples in the "answer" command from the dictionary), was just lucky. It threw Klaus and I. Ahem.
I really recommend using "the" when calling properties. Everyone expects it; you should as well.
I am thrown much more often than Klaus is, I should mention.
Re: how do I encrypt a field?
Posted: Thu Jan 27, 2011 9:07 pm
by Klaus
Hi Rich,
yep, I strongly recommend to stick to the official syntax!
The engine might not be so forgiving in future releases!
And please lookup every unknown and/or new term in the Dictionary
to check the official syntax and get more info about it.
Best
Klaus