How to hide/encrypt password in script?

Hi

I have following problem Im writing a script (in bash ) , where need to be written login & passwd for databas client .
Its need to in following form login passwd@dbhostname .
The problem is so anybody can read it so the passwd & login are visible and thats not very safety .
Can anybody advice me how to hide the details ?
Shall I save it to another file (where the access rights will be restricted ? ) or is there another choice ?
thanks

Thats how I do it... And in the script I read the file to load the content to initialise a variable... but of course Im sure there are other ways...

Can you show us the script?

who's ?

You can use md5hash
echo -n AytosPouRwtaeiEinaiMalakas | md5sum --text > /path/to/save/the/passwd
Then You read the input of the user
Give paswd:****************

if [ `echo -n $UserInput | md5sum --text` = `cat /path/to/saved/passwd` ]; then echo "Login correct"; 
else
echo "try again"; fi
1 Like

to hakermania :

thanks good idea but i need to have it in scripts which will be performed via cron, so I cant use it in my case .

I need to have written: login passwd@host where login & passwd need to be hidden.

You can download the sources of other programs that use the way you want to perform (like ftp in ubuntu (i dont know if it does exist in other OS) i think) and see how they do it.

If running from a cron file, you might consider to run the file from a userid and groupid that cannot be read or executed by other userids. Then, you can "hide" the content by simply making the script file non-readable by other users. You can also put the file in a directory that is not searchable nor readable by other userids.

This is an easy method used by many people to protect sensitive content in files.

... From my mobile phone ....

What database engine is this?
What Operating System is this?
Can you show us what works already (blotting anything confidential)?