LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
reelstuff
- VIP Livecode Opensource Backer

- Posts: 254
- Joined: Mon Apr 16, 2007 12:06 am
-
Contact:
Post
by reelstuff » Thu Jul 17, 2008 3:34 pm
hello, everyone, I am trying to figure out how to use the base64Encode function to encode a string,
username:password
So I can post this to a server online, I tried a couple of different methods of doing this but failed on each occasion, no error presented,
Code: Select all
on mouseUp
put fld "user_name" into myAuth
put ":" after myAuth
put fld "password" after myAuth
put myAuth into fld "testing"
auth_encode
end mouseUp
on auth_encode
return base64encode (myAuth)
put it into fld "encode_test"
end auth_encode
This of course does not work, but it is an example of where I am on this, any feedback, suggestions,
I have tried, several variations of the base64Encode function but I am sure I am missing something important somewhere.
-
malte
- Posts: 1098
- Joined: Thu Feb 23, 2006 8:34 pm
-
Contact:
Post
by malte » Thu Jul 17, 2008 4:13 pm
You will never see it, as a return statement exits the handler, so it will never put something into the field. Also your handler does not know what to encode. I would go for a function I think, or put the encoding part directly into the handler...
Try this:
Code: Select all
on mouseUp
put fld "user_name" into myAuth
put ":" after myAuth
put fld "password" after myAuth
put myAuth into fld "testing"
get auth_encode(myAuth)
-- now do something with it
answer it
end mouseUp
function auth_encode pStringToEncode
local tEncoded
put base64encode (myAuth) into tEncoded
put tEncoded into fld "encode_test" -- for debugging
return tEncoded
end auth_encode
-
reelstuff
- VIP Livecode Opensource Backer

- Posts: 254
- Joined: Mon Apr 16, 2007 12:06 am
-
Contact:
Post
by reelstuff » Thu Jul 17, 2008 5:44 pm
Yes, I see, your right of course,
thank you,
I will put it all in the handler.
Tim
-
reelstuff
- VIP Livecode Opensource Backer

- Posts: 254
- Joined: Mon Apr 16, 2007 12:06 am
-
Contact:
Post
by reelstuff » Thu Jul 17, 2008 7:45 pm
malte wrote:You will never see it, as a return statement exits the handler, so it will never put something into the field. Also your handler does not know what to encode. I would go for a function I think, or put the encoding part directly into the handler...
Try this:
Code: Select all
on mouseUp
put fld "user_name" into myAuth
put ":" after myAuth
put fld "password" after myAuth
put myAuth into fld "testing"
get auth_encode(myAuth)
-- now do something with it
answer it
end mouseUp
function auth_encode pStringToEncode
local tEncoded
put base64encode (myAuth) into tEncoded
put tEncoded into fld "encode_test" -- for debugging
return tEncoded
end auth_encode
This is some interesting stuff here,
anyway, after playing around with the code, here is what came out
bXlBdXRo
which when decoded is myAuth
so the encoding is working correctly, but it is not accepting the var info.
which should something like
username:password
hmm at least I am learning something today, thanks
-
bn
- VIP Livecode Opensource Backer

- Posts: 4163
- Joined: Sun Jan 07, 2007 9:12 pm
Post
by bn » Thu Jul 17, 2008 8:24 pm
Hi,
put on mouseUp
put fld "user_name" into myAuth
put ":" after myAuth
put fld "password" after myAuth
put myAuth into fld "testing"
get auth_encode(myAuth)
-- now do something with it
answer it
end mouseUp
function auth_encode pStringToEncode
local tEncoded
put base64encode (pStringToEncode) into tEncoded
put tEncoded into fld "encode_test" -- for debugging
return tEncoded
end auth_encode
you pass 'myAuth' to the function as 'pStringToEncode'
so if you put
put base64encode (pStringToEncode) into tEncoded
you get what you want
the way it was before the function had no idea what myAuth is supposed to be and it took it as a literal
that is why it always decodes as myAuth
hth
Bernd
-
reelstuff
- VIP Livecode Opensource Backer

- Posts: 254
- Joined: Mon Apr 16, 2007 12:06 am
-
Contact:
Post
by reelstuff » Thu Jul 17, 2008 8:37 pm
bn wrote:Hi,
put on mouseUp
put fld "user_name" into myAuth
put ":" after myAuth
put fld "password" after myAuth
put myAuth into fld "testing"
get auth_encode(myAuth)
-- now do something with it
answer it
end mouseUp
function auth_encode pStringToEncode
local tEncoded
put base64encode (pStringToEncode) into tEncoded
put tEncoded into fld "encode_test" -- for debugging
return tEncoded
end auth_encode
you pass 'myAuth' to the function as 'pStringToEncode'
so if you put
put base64encode (pStringToEncode) into tEncoded
you get what you want
the way it was before the function had no idea what myAuth is supposed to be and it took it as a literal
that is why it always decodes as myAuth
hth
Bernd
Thank you both, yes I see, I was wondering about that,
works like a charm,
-
malte
- Posts: 1098
- Joined: Thu Feb 23, 2006 8:34 pm
-
Contact:
Post
by malte » Thu Jul 17, 2008 9:36 pm
Indeed Bernd.
Sorry for my typo. *blushes*
-
GSPearson
- Posts: 64
- Joined: Tue May 10, 2011 7:39 pm
Post
by GSPearson » Wed Jun 03, 2015 1:59 am
Has anyone else had the following issue with base64encode. I will explain what I am finding.
I have 1 card that is called Register where a user can enter a username, password, first name, last name and email address. On this card I base64encode the password field before sending the information to a web service to write to a database.
On another card I called Login, I have a form where the username and password field. I base64encode the password field on this card before sending it to another web service to check to make sure the account exists and the password is correct.
What I am finding is that on each of these cards, I am getting a different result for base64encode of the same text entered into the password field. If I enter IqmemEsc7 into the password field, and debug the script
On the Register Screen the value of itnow shows: lZWVlZWVlZWV
put base64encode (lPasswordField) into itnow
On the Login Screen the value of itnow shows: SXFtZW1Fc2M3
put base64encode (lPasswordField) into itnow
What would cause the base64encode to display different results on different cards.
-
FourthWorld
- VIP Livecode Opensource Backer

- Posts: 10043
- Joined: Sat Apr 08, 2006 7:05 am
-
Contact:
Post
by FourthWorld » Wed Jun 03, 2015 4:06 am
GSPearson wrote:What I am finding is that on each of these cards, I am getting a different result for base64encode of the same text entered into the password field.
LC's base64Encode function is well tested, and I rely on it daily. Given the same input it will produce the same output, so if your output is varying check your inputs.
As a side note, unless you're using SSL it may be useful to encrypt the authentication data before sending it over the wire, or better yet never send it at all but merely a hash of it such as the output from the md5Digest or sha1Digest functions.