Say I wanted to create something like how cPanel works, it uses the username and password from the system.
You can run 'passwd user' on the server, and the password would still work with cPanel and FTP (not necessarily MySQL, but you get the point)
How would I accomplish this in PHP? I haven't the slightest idea, besides running /bin/su locally and running from that. With that, it might be inaccurate though.. I usually have a few of my developers either on a sub-account, or on root developing something.
Any ideas would greatly be appreciated, thanks! :)
Linux Authentication. Authentication is the formal sysadmin term for logging into the system. It's the process of a user proving that she is who she says she is to the system. This is generally done via a password, though it can be accomplished via other methods such as fingerprint, PIN, etc.
After authentication, the PHP $_SESSION super global variable will contain the user id. That is, the $_SESSION[“member_id”] is set to manage the logged-in session. It will remain until log out or quit the browser. While logout, we unset all the session variables using the PHP unset() function.
Once the user has filled in a username and a password, the URL containing the PHP script will be called again with the predefined variables PHP_AUTH_USER , PHP_AUTH_PW , and AUTH_TYPE set to the user name, password and authentication type respectively. These predefined variables are found in the $_SERVER array.
PAM: http://pecl.php.net/package/PAM
In Debian /'buntu packages, it is probably as easy as installing php5-auth-pam, and using the function:
pam_auth($username,$password,$error);
Although it seems to rely on ancient php4 syntax, 'cause I get an error if I don't use the deprecated way of passing by reference at call time:
if(!pam_auth($username,$password,&$error)){
echo 'No access, PAM said: '.$error;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With