Script to change Unix password

Hi All,
I am new to unix env.
I have a doubt.
My situation is that i need to write a shell script
to change the password of the existing user name and take the
new password encrypt it and save it in the db2 database.

my thought process is

i will echo the following

Please enter the old password :xxx
please enter the new password : yyy
retype the new password : yyy

store these in a variable and need to do some encrption
and store the value in the db2 table.

Popular White Paper On This Topic

Hi,
You can easily do this by doing md5 hash of the password.
c version is md5.h. U wil find programs in c for performing md5 hash on the password string to help you out i am pasting the code used by me here

also java.security package allows the md5 hash on the string then ucan store it in the database.

But u beware managing it with using salts for paswords. brute force hacking program can easliy hack the passwords with arnd 6 length witthin 2 days.
but u better of leeting do all these things and make ur database create a password. in oracle u can easily do it. by util_package which lets u crate new users and specify passowrds.
Hope u will find this info useful.
Regards,
abhjit Joshi

I have used the expect program to handle password changes.
Expect scripts can be programmed to issue the passwd command and then to look for the prompts from the passwd command and respond to them.
Selwyn Schultz
Herman Miller Inc.
e-mail: email@removed
Phone: 616 654-7257
Fax: 616 654-5295

I suppose the reason you feel the need to write a shell script for changing passwords is so that you can store them in a database. Now why would you want to do that? If you're doing this so that an admin can recover any password, then it seems pointless. The root user can always override any password anyway. All you do is decrease security by storing passwords in yet another place.

Password command require the SUID value set to change the password in
the Systems. that is nothing but the root id while chaging the password.
by shell script it is not possible to achive it as, unix ignore the SUID
set on any file otherthan a binary.
regards
Rajani

First thing, as pointed out by Norman, why do you want to store the new password in db2? If you are looking for a script that can change the password, I have written a perl script to automate the password change, you need to have perl installed on your system to run this. If not use the expect utility and the logic remains same i.e it is based on the patteren matching technique.