asp.net - 用户无需在本地主机上提供密码即可登录

标签 asp.net forms-authentication

我有一个基于 C# 的带有表单例份验证的 Asp.net 网站。我们使用 Active Directory 对用户进行身份验证,一切正常。但是今天我们意识到只需输入用户名并单击“登录”即可登录任何帐户,而无需提供任何密码!这仅发生在本地主机上运行的开发环境中(谢天谢地!),但我不喜欢它......

我以前从未见过这种行为,真的很想有人解释这是怎么发生的。这是 Microsoft 构建的开发人员功能吗?还是我办公室的某个人在没有告诉其他人的情况下制作了后门?我将进一步调查最后一个选项,但在那之前 - 有没有人遇到过这个问题?

非常感谢提前!

编辑:
这是身份验证为我抛出的每个用户名返回 true 的地方 - 密码为空。其他密码返回false。

using (var context = new PrincipalContext(ContextType.Domain))
{
   result = context.ValidateCredentials(username, password);
}
PrincipalContextSystem.DirectoryServices.AccountManagement 的默认值

最佳答案

经过更多调查,我发现 this在 MSDN 上指出:

The ValidateCredentials method binds to the server specified in the constructor. If the username and password parameters are null, the credentials specified in the constructor are validated. If no credential were specified in the constructor, and the username and password parameters are null, this method validates the default credentials for the current principal.



以及 constructor 的文档中的这些信息的 PrincipalContext :

public PrincipalContext(System.DirectoryServices.AccountManagement.ContextType contextType, string name):
contextType: A System.DirectoryServices.AccountManagement.ContextType enumeration value specifying the type of store for the principal context.
name: The name of the domain or server for System.DirectoryServices.AccountManagement.ContextType.Domain context types, the machine name for System.DirectoryServices.AccountManagement.ContextType.Machine context types, or the name of the server and port hosting the System.DirectoryServices.AccountManagement.ContextType.ApplicationDirectory instance. If the name is null for a System.DirectoryServices.AccountManagement.ContextType.Domain context type this context is a domain controller for the domain of the user principal under which the thread is running. If the name is null for a System.DirectoryServices.AccountManagement.ContextType.Machine context type, this is the local machine name. This parameter cannot be null for System.DirectoryServices.AccountManagement.ContextType.ApplicationDirectory context types.



这使我得出结论,因为我不使用 name PrincipalContext 的构造函数中的属性,域 Controller 将在我的开发机器上运行在我自己的主体下。这可能意味着它使用我的用户权限,这当然比生产服务器运行的机器帐户高得多。这反过来可以使所有调用Validatenull由于更高级别的特权,密码会自动验证。

至少,这是我的理论......欢迎评论和想法,我将很快结束这个问题。

关于asp.net - 用户无需在本地主机上提供密码即可登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5069956/

相关文章:

asp.net-mvc - ASP.NET MVC - 根据 Active Directory 对用户进行身份验证,但需要输入用户名和密码

asp.net - Web.HttpContext.Current.User.Identity.Name来自何处?

.net - 如何在 ASP.NET MVC 中重定向到动态登录 URL

asp.net-mvc - 如何在请求早期使错误的身份验证 cookie 失效?

asp.net - 表单例份验证和身份验证票证 cookie 域

asp.net - 测量 Web 请求和响应的大小

c# - 隐藏 GridView ID 列

asp.net - 嵌套 HTML 表格的渲染问题(性能)

c# - 测试将对象作为参数的 GET 请求(Asp.NET WebApi Controller )

c# - 在 DropDownList 中添加分隔符