views:

40

answers:

2

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

+2  A: 

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;
}
Wrikken
Thank you, I haven't seen this module before. I'll experiment with it and see how it goes.
Billy
A: 

It's not really clear what you want to authenticate. In any case, you could use PAM with PHP: http://pecl.php.net/package/PAM

There is that PHP function: posix_getpwnam

You could use that quite straight forward as well.

sims