使用本地用户帐户在 Windows 上进行基于 PHP 表单的身份验证

标签 php windows apache authentication sam

我正在运行 PHP、Apache 和 Windows。我没有域设置,所以我希望我网站的基于表单的身份验证使用 Windows 内置的本地用户帐户数据库(我认为它称为 SAM)。

我知道如果设置了 Active Directory,您可以使用 PHP LDAP 模块在脚本中进行连接和身份验证,但是没有 AD 就没有 LDAP。独立机器的等价物是什么?

最佳答案

我也没有找到简单的解决方案。有一些使用 CreateObject 和 WinNT ADSI 提供程序的示例。但最终他们都碰到了 User authentication issues with the Active Directory Service Interfaces WinNT provider .我不是 100% 确定,但我猜想 WSH/网络连接方法有同样的问题。
根据How to validate user credentials on Microsoft operating systems您应该使用 LogonUser 或 SSPI。
它还说

LogonUser Win32 API does not require TCB privilege in Microsoft Windows Server 2003, however, for downlevel compatibility, this is still the best approach.

On Windows XP, it is no longer required that a process have the SE_TCB_NAME privilege in order to call LogonUser. Therefore, the simplest method to validate a user's credentials on Windows XP, is to call the LogonUser API.

因此,如果我确定不需要 Win9x/2000 支持,我会编写一个将 LogonUser 公开给 php 的扩展。
您可能还对 User Authentication from NT Accounts 感兴趣.它使用 w32api 扩展,需要一个支持 dll ...我宁愿写那个小的 LogonUser 扩展 ;-)
如果这不可行,我可能会研究 IIS 的 fastcgi 模块及其稳定性,然后让 IIS 处理身份验证。

编辑:
我也尝试过使用 System.Security.Principal.WindowsIdentity和 php 的 com/.net extension .但是 dotnet 构造函数似乎不允许将参数传递给对象构造函数,而我从 GetType() 获取程序集(及其 CreateInstance())的“实验”失败并出现“未知 zval”错误。

关于使用本地用户帐户在 Windows 上进行基于 PHP 表单的身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60585/

相关文章:

php - 具有现有值的 PDO 更新表?

windows - 为什么我的 Qt 4.5 应用程序在 Windows 下打开一个控制台窗口?

.net - 我可以将 32 位 DLL 加载到 Windows 上的 64 位进程中吗?

apache - NGINX proxy_pass 到另一个端口

java - 在 Ubuntu 上的 Eclipse 中设置 Tomcat

django - Apache Django Mod_Wsgi-自动重新加载

php - 如何在laravel的 Blade 文件中显示最新的('updated_at')记录

php - 如何将 Dart 项目与 PHP 相结合?

php - MySql插入查询返回2条记录

c++ - MSBuild.exe 不并行构建项目