Operating System - HP-UX
1834395 Members
1586 Online
110066 Solutions
New Discussion

How to encrypt password within scripts

 
SOLVED
Go to solution
Aji Thomas
Regular Advisor

How to encrypt password within scripts

Hi guys,

I have a database script that contains system password within it. How can i encrypt the password with any other character.

Similarly, is there a way the script will prompt me for the password and i can type in the system password, in encrypted format.
And when the backup will be scheduled it will take the encrypted password.

Please advice us,
AJi

Please advice me
6 REPLIES 6
Alex Lavrov.
Honored Contributor

Re: How to encrypt password within scripts

You have "crypt" command.

But be sure that the encrypting algorithm of DB is the same of "crypt".

Alex.
I don't give a damn for a man that can only spell a word one way. (M. Twain)
RAC_1
Honored Contributor
Solution

Re: How to encrypt password within scripts

There are compilers for shell scripts. you may look at those products. like shelllock or something similar.

Otherwise, you can not encrypt the pass in a shell file. What you can do is put following code, that will supress, the echo of the password.

trap 'stty echo; exit' 0 1 2 3 15
echo "Enter Password: \c"
stty -echo
read PASSWD
stty echo
There is no substitute to HARDWORK
Aji Thomas
Regular Advisor

Re: How to encrypt password within scripts

Hi RAC,

Thanks for the advice,
I want to verify the password matches with the database.
How can i achieve that?

Something like including
sqlplus system/$PASSWD

when i tried to include its shows the output, i want to run this autentication in the background. Please advice me

AJi
RAC_1
Honored Contributor

Re: How to encrypt password within scripts

do your password check as follows.

stty -echo
your code for check goes here
some more code
stty echo

Anything between stty -echo and stty echo
will not be displayed to the screen.
You can also do re-directon of std out, std err to /dev/null

"check_statement" > /dev/null 2>&1

There is no substitute to HARDWORK
Alex Lavrov.
Honored Contributor

Re: How to encrypt password within scripts

Oh, by encrypted method you ment so the password will not be shown on the screen, I thought you wanna encrypt it before using.


Try:

sqlplus -L user/password > /dev/null 2>&1

echo $?

So, if "$?" is 0, login was ok, if not, login failed. -L option says to try login only once and exit and all the output we redirect to /dev/null.


Alex.
I don't give a damn for a man that can only spell a word one way. (M. Twain)
Aji Thomas
Regular Advisor

Re: How to encrypt password within scripts

Hi

Guys, its working fine.
In my script i included as follows,

-------------------------------------------
trap 'stty echo; exit' 0 1 2 3 15
echo "Enter Password: \c"
stty -echo
read PASSWD

sqlplus -L system/$PASSWD@prod < /dev/null 2>&1
exit
EOF1
exit_code="$?"

if test "$exit_code" = "1"; then
printf "\nLogin failed\n";
else
printf "\nLogin Success\n";
fi
-------------------------------------

Regards
AJi