note
mdillon
First, you need to generate an appropriate salt. The code provided by [tadman] in [id://62392|this node] should work.
<p>Then, either install [cpan://Crypt::PasswdMD5] and use:
<code>use Crypt::PasswdMD5;
my $crypted = unix_md5_crypt $passwd, $salt;</code>
Or, since you're apparently using RedHat (since adduser is a RedHat-specific command AFAIK) and your libc's crypt should do MD5-crypt automatically given a proper MD5 salt, use:
<code>my $crypted = crypt $passwd, $salt;
</code>
To make sure this works, print the value of <tt>$crypt</tt>; it should be something like <tt>$1$b1yv9grF$mpwoS2r11VtENFrAmF2WW/</tt> (instead of the shorter string returned by traditional DES-crypt). Once you've confirmed that you have what looks like an MD5-crypted password, use the value of <tt>$crypted</tt> in your command line:
<code>system("adduser", "bob", "-p", $crypted) == 0
or die "Error adding user 'bob': $!$/";</code>
The secret to getting crypt to work correctly is in providing a salt starting with '$1$' and having 8 characters (instead of the normal 2 used for DES-crypt). There are similar conventions for using other crypt variants (e.g. '$2$' for SHA-crypt).
198592
198841