how do I encrypt a field?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

krawson1
Posts: 3
Joined: Thu Jan 20, 2011 3:00 pm

how do I encrypt a field?

Post by krawson1 » Thu Jan 20, 2011 3:06 pm

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?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10058
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: how do I encrypt a field?

Post by FourthWorld » Thu Jan 20, 2011 4:17 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: how do I encrypt a field?

Post by dunbarx » Thu Jan 20, 2011 5:31 pm

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

krawson1
Posts: 3
Joined: Thu Jan 20, 2011 3:00 pm

Re: how do I encrypt a field?

Post by krawson1 » Thu Jan 20, 2011 5:58 pm

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!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: how do I encrypt a field?

Post by dunbarx » Thu Jan 20, 2011 8:45 pm

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

krawson1
Posts: 3
Joined: Thu Jan 20, 2011 3:00 pm

Re: how do I encrypt a field?

Post by krawson1 » Thu Jan 20, 2011 11:37 pm

This is incredibly helpful, thank you so much for your prompt replies and advice!!

Cheers,
Katherine

richh
Posts: 41
Joined: Tue Jan 25, 2011 8:48 pm

Re: how do I encrypt a field?

Post by richh » Thu Jan 27, 2011 3:34 pm

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?
- Rich

LiveCode 4.6.4
Dell Latitude E6400 running Windows XP SP3 / Mac Pro, Macbook Pro & Mac Mini running OS X 10.6.4

Klaus
Posts: 14212
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: how do I encrypt a field?

Post by Klaus » Thu Jan 27, 2011 4:18 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: how do I encrypt a field?

Post by dunbarx » Thu Jan 27, 2011 6:26 pm

"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.

richh
Posts: 41
Joined: Tue Jan 25, 2011 8:48 pm

Re: how do I encrypt a field?

Post by richh » Thu Jan 27, 2011 7:18 pm

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
- Rich

LiveCode 4.6.4
Dell Latitude E6400 running Windows XP SP3 / Mac Pro, Macbook Pro & Mac Mini running OS X 10.6.4

Klaus
Posts: 14212
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: how do I encrypt a field?

Post by Klaus » Thu Jan 27, 2011 7:46 pm

Hi Rich,

clean your glasses, please! :D

As we already unmistakably wrote in our postings:
...
answer THE currentData of fld 1
...
8)


Best

Klaus

richh
Posts: 41
Joined: Tue Jan 25, 2011 8:48 pm

Re: how do I encrypt a field?

Post by richh » Thu Jan 27, 2011 7:55 pm

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 :P
- Rich

LiveCode 4.6.4
Dell Latitude E6400 running Windows XP SP3 / Mac Pro, Macbook Pro & Mac Mini running OS X 10.6.4

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: how do I encrypt a field?

Post by dunbarx » Thu Jan 27, 2011 8:38 pm

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.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: how do I encrypt a field?

Post by dunbarx » Thu Jan 27, 2011 9:00 pm

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.

Klaus
Posts: 14212
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: how do I encrypt a field?

Post by Klaus » Thu Jan 27, 2011 9:07 pm

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

Post Reply