Click to See Complete Forum and Search --> : Verifying NT Accounts from PHP


PontusM
09-27-2002, 09:10 AM
Hi!

I´m currently porting an old webbased system into a better layout and a whole new databasestructure.

One annoying thing with the old system is that it is separate from all other systems and users are complaining about being forced to remember diffrent logins for diffrent systems so I thought about it and started writing a structure that allows other servers to OK users.

The other system can only ok the login and everything is is handled locally.

After a couple of hours of searching and discussing it with a friend I have found no stable solution to do this and thats why I´m posting here.

I have found some code to authenticate users but once this coded has been proccessed it cannot be proccessed again until you recycle the process.

The function:
function NT_Validate_User($user, $domain, $pass) {
w32api_register_function("ValidateLogin.dll", "ValidateLogin", "bool");
return ValidateLogin($user,$domain,$pass);
}

Validate.c:

#include <windows.h>
__declspec(dllexport) BOOL ValidateLogin(LPTSTR lpszUsername,LPTSTR lpszDomain,LPTSTR lpszPassword) {
HANDLE token;
BOOL ret;
ret=LogonUser(lpszUsername,lpszDomain,lpszPassword,LOGON32_LOGON_NETWORK,LOGON32_PROVIDER_DEFAULT,&token);
if(ret)
CloseHandle(token);
return ret;
}

This forces the platform that validates the NT user to be a Windows platform but that is no big issue.

I want to keep it in a function to just validate a user/pass/domain and it must work with both NT domains and the new Active Directory.

Perhaps I should just scrap the old NT domains and keep every user either in the separate databse for the webapplication and check the AD with ldap.

But maybe someone can help?

I like to keep my code platform independant and keep developing on two platforms:
1. .NET Server RC1 / IIS 6 / PHP 4.2.3
2. RedHat 6.2 / Apache/1.3.12 / PHP 4.0.6

/ p.

raceeend
10-02-2002, 02:56 PM
userserver (http://www.armcad.narod.ru/userserver.zip) should help if you want to authenticate against th NT userdatabase.

Runs fine for me.

regards,
Martijn

PontusM
10-03-2002, 04:58 AM
Thanks Martijn!

Perfect! Exactly what I was looking for!

/ p.

apaxson
10-12-2002, 03:13 AM
Great little program!! I see alot of uses out of it. In my corporate environment, we have a triple domain infrastructure. It seems all I have to do, is install the service on each of the PDC's. Then, depending on the domain the user selects, have PHP query the appropriate server. Sounds like it would work, wouldn't it?

One question, while this seems like it will solve a problem I have with a current project I'm building, we are going to be moving to an Active Directory within 6 mos. Would this still work in Windows2000?????

Huge thanks in advance!!

raceeend
10-13-2002, 08:53 AM
Glad it works,

Dont know if it works with win2k havent tested it.

regards,
Martijn

guzman-el-bueno
10-22-2002, 04:17 AM
Hi,

sounds like the problem is solved, and great link to that site!
thanks for posting that for everyone to see...

i was going to suggest that you try setting up a samba server
and have that replicate a copy of your user database, and then
you can authenticate php against that. samba is very flexible
in that because it can actually serve as a domain controller in
that sense.

but anyway, problem solved in what amounts to probably a much
easier and less time-consuming way!

cheers!