Page 1 of 1

using base64Encode to return encoded string

Posted: Thu Jul 17, 2008 3:34 pm
by reelstuff
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.

Posted: Thu Jul 17, 2008 4:13 pm
by malte
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 

Thank y0u

Posted: Thu Jul 17, 2008 5:44 pm
by reelstuff
Yes, I see, your right of course,

thank you,

I will put it all in the handler.

Tim

Posted: Thu Jul 17, 2008 7:45 pm
by reelstuff
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

Posted: Thu Jul 17, 2008 8:24 pm
by bn
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

Posted: Thu Jul 17, 2008 8:37 pm
by reelstuff
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,

Posted: Thu Jul 17, 2008 9:36 pm
by malte
Indeed Bernd.

Sorry for my typo. *blushes*

Re: using base64Encode to return encoded string

Posted: Wed Jun 03, 2015 1:59 am
by GSPearson
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.

Re: using base64Encode to return encoded string

Posted: Wed Jun 03, 2015 4:06 am
by FourthWorld
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.