Bir PHP uzantısı bina sabit disk alanı açısından oldukça büyük bir yatırım gerektirir. Ben zaten GCC (MinGW'nin) ortamında yüklü beri, PHP komut bir süreci başlatma başarımdan almaya karar verdik. Kaynak kodu aşağıda.
// Usage: logonuser.exe /user username /password password [/domain domain]
// Exit code is 0 on logon success and 1 on failure.
#include <windows.h>
int main(int argc, char *argv[])
{
HANDLE r = 0;
char *user = 0;
char *password = 0;
char *domain = 0;
int i;
for(i = 1; i < argc; i++)
{
if(!strcmp(argv[i], "/user"))
{
if(i + 1 < argc)
{
user = argv[i + 1];
i++;
}
}
else if(!strcmp(argv[i], "/domain"))
{
if(i + 1 < argc)
{
domain = argv[i + 1];
i++;
}
}
else if(!strcmp(argv[i], "/password"))
{
if(i + 1 < argc)
{
password = argv[i + 1];
i++;
}
}
}
if(user && password)
{
LogonUser(user, domain, password, LOGON32_LOGON_BATCH, LOGON32_PROVIDER_DEFAULT, &r);
}
return r ? 0 : 1;
}
Next is the PHP source demonstrating its use.
$user = "";
$domain = "";
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
if(isset($_REQUEST['user'], $_REQUEST['password'], $_REQUEST['domain']))
{
$failure = 1;
$user = $_REQUEST['user'];
$password = $_REQUEST['password'];
$domain = $_REQUEST['domain'];
if($user && $password)
{
$cmd = "logonuser.exe /user " . escapeshellarg($user) . " /password " . escapeshellarg($password);
if($domain) $cmd .= " /domain " . escapeshellarg($domain);
system($cmd, $failure);
}
if($failure)
{
echo("Incorrect credentials.");
}
else
{
echo("Correct credentials!");
}
}
}
?>
<form action="<?php echo(htmlentities($_SERVER['PHP_SELF'])); ?>" method="post">
Username: <input type="text" name="user" value="<?php echo(htmlentities($user)); ?>" /><br />
Password: <input type="password" name="password" value="" /><br />
Domain: <input type="text" name="domain" value="<?php echo(htmlentities($domain)); ?>" /><br />
<input type="submit" value="logon" />
</form>