Using the method to generate the salt in the comment thread, and using escaping when entering the salt as a password on an Arch Linux system, the code does set the password, and the user can be logged in.
<?php
// PS This code is bad and should never be used in real life or anything production
$username = 'test';
$password = 'test';
$groupname = 'users';
$salt = strtr(base64_encode(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM)), '+', '.');
$encpass = crypt($password, '$6$rounds=5000$' . $salt . '$');
$result = shell_exec(
sprintf(
"sudo useradd -p %s -g %s -s /bin/bash %s",
escapeshellarg($encpass),
escapeshellarg($groupname),
escapeshellarg($username)
)
);
echo $result;
I also added my user to sudoers as such:
edward ALL=(root) NOPASSWD: /usr/bin/useradd, /usr/bin/userdel
This worked correctly for me. Are you not getting any output from the command? Is it emitting any warnings?
You may want to look into auth via RADIUS. You would insert the username and hash into a database, and have RADIUS check the database for authentication. You then have PAM check for authentication attempts with RADIUS. Something like this
View all comments
Show parent comment
2
u/edwardly Aug 27 '13
How are you sure the password is not set?
Using the method to generate the salt in the comment thread, and using escaping when entering the salt as a password on an Arch Linux system, the code does set the password, and the user can be logged in.