>From shelden@spoke.law.cornell.edu Wed Sep 29 08:54:53 1993 Subject: Generate random passwords for adduser. Sure. Whenever I write an adduser script, I have it generate a random password, and use that password as the initial person's password. Keeps many future problems at bay. Below is some perl to generate and encrypt random passwords. You could either use my code to roll your own adduser program, or to filter /etc/passwd after you run add_user. #! /usr/local/bin/perl -w srand($$|time); $ascii_passwd = &pw_generate; # What the user must type $epasswd = &pw_encrypt($ascii_passwd); # What goes in /etc/passwd #------------------------------------------------------------------------------ # Generate funky random password: #------------------------------------------------------------------------------ sub pw_generate { local(@passset, $rnd_passwd, $randum_num); local($randum_num); # Since 1 ~= l and 0 =~ O, don't generate passwords with them. # This will just confuse people using ugly fonts. # @passset = ('a'..'k', 'm'..'z', 'A'..'N', 'P'..'Z', '2'..'9'); $rnd_passwd = ""; for ($i = 0; $i < 8; $i++) { $randum_num = int(rand($#passset + 1)); $rnd_passwd .= @passset[$randum_num]; } return $rnd_passwd; } #----------------------------------------------------------------------------- # Returns its argument encrypted with a random salt. #----------------------------------------------------------------------------- sub pw_encrypt { local($passwd) = @_; local($ascii_salt, $randum_num, @passset, $epasswd); @passset = ('a'..'k', 'm'..'z', 'A'..'N', 'P'..'Z', '2'..'9'); $ascii_salt = ""; for ($i = 0; $i < 10; $i++) { $randum_num = int(rand($#passset + 1)); $ascii_salt .= @passset[$randum_num]; } $salt = `echo "$ascii_salt" | /usr/lib/makekey`; $epasswd = crypt($passwd, $salt); return $epasswd }