Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How would I use PHP to authenticate with Linux users and passwords?

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! :)

like image 213
Billy Avatar asked Sep 21 '10 23:09

Billy


People also ask

How do users authenticate in Linux?

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.

Which of the following PHP functions is used to make a user logged out from a website?

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.

How do I set basic authentication in HTTP header PHP?

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.


1 Answers

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;
}
like image 192
Wrikken Avatar answered Sep 24 '22 10:09

Wrikken