Error executing shell echo command through LC

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Error executing shell echo command through LC

Post by kaveh1000 » Wed Dec 12, 2018 10:49 am

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

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: Error executing shell echo command through LC

Post by bogs » Wed Dec 12, 2018 1:18 pm

Dunno, from Mc to 8.1.2, your code seems to work here on 'nix ~
Selection_001.png
CLI hashed passwords...
Image

wsamples
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 262
Joined: Mon May 18, 2009 4:12 am

Re: Error executing shell echo command through LC

Post by wsamples » Wed Dec 12, 2018 4:36 pm

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.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Error executing shell echo command through LC

Post by FourthWorld » Wed Dec 12, 2018 6:29 pm

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

kaveh1000
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 508
Joined: Sun Dec 18, 2011 7:23 pm
Location: London
Contact:

Re: Error executing shell echo command through LC

Post by kaveh1000 » Fri Dec 14, 2018 8:06 am

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

Post Reply

Return to “Talking LiveCode”