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