How to write the password to result_p.txt in encrypted form and how retrieve it back as well?
echo "Please enter the mysql root password : "
stty -echo
read PASSWORD
echo $PASSWORD > result_p.txt
stty echo
if [[ "$PASSWORD"开发者_如何学Python = "amma" ]]
then
echo "Entered Mysql password is :" $PASSWORD
fi
You could use a small Python script to obfuscate it using Base64:
#!/usr/bin/env python
import getpass
password = getpass.getpass()
open("result_p.txt", "w").write(password.encode("base64"))
Then to read the password:
password = open("result_p.txt").read().decode("base64")
I'm afraid that it has no sense while user can view contents of your shell script. IMHO, the most simple way would be 'chmodding' resultant *result_p.txt* so that it is not readable by regular user.
精彩评论