[Hampshire] [OT] Linux compatible crypt(3) password from Per…

Top Page

Reply to this message
Author: Damian Brasher
Date:  
To: Hants Lug
Subject: [Hampshire] [OT] Linux compatible crypt(3) password from Perl
I am writing subroutine to generate a Linux compatible password for the
command useradd executed from within a Perl script, where useradd can be
supplied a compatible encrytped password as with crypt(3) generated
passwords. I need something like this:

my $ADD_USER="/usr/sbin/useradd -g users -G sshd -d /home/n_user -m -p
${crypt_user_pass} n_user";

The Perl function, crypt, needs a salt to generate a password, so to generate
the above variable ${crypt_user_pass} I have something like:

my $salt = substr($new_pass,0,2); # use first 2 chars of new password for salt
$crypt_user_pass = crypt($new_pass, $salt); # encrypt pass

Unfortunately the generated crypted password does allow access so is possibly
incorrect. It does not match that which is present in /etc/shadow if you
manually add a user.

Can anyone see where I'm going wrong? Does anyone have a working example they
can point me to?

Time to dig out Applied Cryptography too;)

Thanks, Damian

--
WWW http://www.diaser.org.uk - working together to make long term digital
archives more accessible

RSS http://sourceforge.net/export/rss2_projfiles.php?group_id=258272

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.