Page 1 of 1

Error executing shell echo command through LC

Posted: Wed Dec 12, 2018 10:49 am
by kaveh1000
A colleague is trying to use the “echo” shell command on a Mac, through LiveCode, in order to return an encrypted password through a Stack. The code is as follows:

Code: Select all

 set the usrname of this stack to the text of fld "user_name_fld"
 put the text of fld "password_fld" into pwd  
 put shell ("echo -n "&pwd &" | md5sum") into Encypted_pswd
We get an error in the following form:

Code: Select all

/bin/sh: line 1: md5sum: command not found.
When entered directly in Terminal in Mac, echo produces a result without an error.

Any ideas of what we are doing wrong?

Re: Error executing shell echo command through LC

Posted: Wed Dec 12, 2018 1:18 pm
by bogs
Dunno, from Mc to 8.1.2, your code seems to work here on 'nix ~
Selection_001.png
CLI hashed passwords...

Re: Error executing shell echo command through LC

Posted: Wed Dec 12, 2018 4:36 pm
by wsamples
Try using the whole path to md5sum in your command. This kind of problem commonly arises because the command is not in the PATH of the shell being used by the Livecode shell() function. That's always the first thing to check when the function fails but the command works in your user terminal. You could also get the PATH in a function and check to see if md5sum is somewhere in that path.

Re: Error executing shell echo command through LC

Posted: Wed Dec 12, 2018 6:29 pm
by FourthWorld
kaveh1000 wrote:
Wed Dec 12, 2018 10:49 am
...to return an encrypted password through a Stack...

Code: Select all

/bin/sh: line 1: md5sum: command not found.
Do you need encryption or hashing? For a password hashing is (almost always) best, but I want to make sure I understand the usage before drawing conclusions.

Do you need to use the OS shell command for the hash?

If you can use LC's built-in functions, three are available: md5digest, sha1digest, and messageDigest.

The first two are legacy, while messageDigest supports both md5 and sha1 as specifiable algos.

More importantly, messageDigest also supports more modern and secure algos. Currently these include sha2 and sha3, which should ideally be used for modern password hashing, as there are known collisions with both md5 and sha1.

Salting is also considered good practice, but we can get to that once we have a better understanding of what you're looking to do.

Re: Error executing shell echo command through LC

Posted: Fri Dec 14, 2018 8:06 am
by kaveh1000
Thank you all for the comments. I am a bit new to this so learning some background.

Using the whole path might be the solution.

And Richard, thank you for the hints of using LC's commands which we did not know about.

I will report back on our progress...