Hi,

I've been trying to have PHP generate an encrypted MD5 password, which i
want to include in the adduser shell command.

/usr/sbin/useradd -g www -s /bin/bash -p '$pass' user

the $pass has to be the MD5 encrypted password.

I have found usefull hint in the crypt function description on
php.net. I have managed to produce a MD5 encrypted version of a clear-text
password through the PHP function call. But after executing the useradd
command, I cannot login into the system.

What possibly went wrong ?

Cheers,

Bram van den Hout
bram@braminator.com

    you mast pass to useradd clear text password

      Hmm, not according to the manpage - useradd(1). Or am i missing something ?

      Thx for the quick answer !

      Bram


      NAME
      useradd - Create a new user or update default new user information

      SYNOPSIS
      useradd [-c comment] [-d home_dir]

      ---CUT---CUT---CUT---CUT---CUT---CUT---CUT
      -p passwd
      The encrypted password, as returned by crypt(3). The default is to disable the account.

        Since when does crypt() do md5 and not DES? Try crypt()-ing it instead.

          LINUX PASSWD file is based on DES, you need to pass an encrypted password into useradd in order for you to logon. useradd assumes that the password is already a DES encrypted password. DO crypt() before executing useradd

          Jun

            I'm afraid i've lost you there.

            How do I : "crypt() before executing useradd" ?

            Is this a command I can execute in a BASH shell ?

            I've read : man crypt, but didn't understand much of it.

            Thankx,

            Bram van den Hout

              5 months later

              yes, it does

              from online manual:
              (http://www.zend.com/manual/function.crypt.php)
              PHP sets a constant named CRYPT_SALT_LENGTH which tells you whether a regular 2-character salt applies to your system or the longer 12-char MD5 salt is applicable.

              CRYPT_MD5 - MD5 encryption with a 12-char SALT starting with $1$

              i'm not sure how unix md5 passwords in shadow file is made, but they'll start with $1$

              this one worked on my system:
              echo "Adding user to system...";
              $usrAddCmd = "adduser $new_user -d /crap/home/$new_user -g $group -p ".crypt($new_pass)." -n -s /bin/bash";
              exec($usrAddCmd);

              it didn't create md5 string, but allowed me to login...

              Kirk Parker wrote:

              Since when does crypt() do md5 and not DES? Try crypt()-ing it instead.

                6 months later

                man, crypt() is a php function
                www.php.net/crypt
                😉

                  Write a Reply...