[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: useradd and passwd

On Thu, 10 May 2001, Vivek Chawla wrote:

> But how do I generate that encrypted password from a simple password in a
> shell script or a perl script.
> The crypt function mentioned is a c library function ?

See attached perl script.  Call it with
	./mkpasswd username passwd

Sanjeev "ghane" Gupta                    Mob: +65 98551208
dotXtra Pte Ltd                          Fax: +65 2275776
Singapore                                email: ghane@xxxxxxxxxxx
# pop_passwd username password >> password file

 $name = $ARGV[0];

 @salt_chars         = ('a'..'z','A'..'Z','0'..'9');
 $salt               = $salt_chars[rand(62)] . $salt_chars[rand(62)];

 $passwd = crypt ($ARGV[1], $salt);

 print "$name:$passwd\n";