如何使用Windows身份验证检查用户名和密码? [英] How to check user name and password using Windows authentification?

查看:274
本文介绍了如何使用Windows身份验证检查用户名和密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序是使用ASP.net创建的,并且身份验证使用的是Windows身份验证。令我困惑的是,

这里他们使用WCF来检查用户名。这个WCF很新。

所以我只是想知道他们是如何通过Windows身份验证从WCF应用程序检查用户名和密码的?

哪一种是通常的方法?

我想分析代码并制作报告,请帮助我。

My application is created using ASP.net and the authentication is using Windows authentication.Its confusing me,
here they have used WCF for checking user name.Am very new to this WCF.
So i just want to know how they are checking the user name and password from WCF application via windows authentication?
Which one is usual method??
I want to analyze the code and make the report so please help me.

推荐答案

我知道Web应用程序可以通过2种方式进行Windows身份验证:



第一个:使用IIS,如果页面存储在访问受限的目录中(例如使用NTFS访问权限),将提示客户端输入登录名和密码。 />
服务器将接收这些(加密与否,取决于IIS配置),并且将使用这些凭据调用ASP.NET对象(如果授予访问权限)。



第二个:没有服务器权限管理在应用程序中完成的每件事情都是如此。在这种情况下,应用程序可以调用Windows函数登录到其他帐户(如模拟)
I know 2 ways a web application can do Windows Authentication :

First one : with IIS, if the page is stored in a directory with restricted access (using NTFS access rights for example), the client will be prompted to enter login and password.
The server will receive those (encrypted or not, depending of the IIS configuration) and the ASP.NET object will be called using those credentials (if access granted).

Second one : no server right management, every thing done in the application. In this case, the application may call the Windows function to login to an other account (like in impersonation)
[DllImport("AdvApi32.dll")]
extern static bool LogonUser(string username, string password, string domain, UInt32 LogonType, UInt32 LogonProvider, ref IntPtr hToken); 



然后,您可以使用System.Security.Principal.WindowsIdentity来管理C#中的帐户,并在必要时进行模拟。


Then you can use the System.Security.Principal.WindowsIdentity to manage the account in C# and do the impersonate if necessary.


您可以使用PrincipalContext类来验证用户凭据。使用登录窗口获取域,用户ID和密码,并进行如下验证。



//使用System.DirectoryServices.AccountManagement添加此参考

;



//使用此代码进行身份验证

PrincipalContext pc = new PrincipalContext(ContextType.Domain,txtDomain.Text);

bool bResult = pc.ValidateCredentials(txtUserId.Text ,txtPassword.Text);
You can use PrincipalContext class to validate user credentials. Get domain, userid and password using a login window and validate as follows.

//Add this reference
using System.DirectoryServices.AccountManagement;

//Use this code for authentication
PrincipalContext pc = new PrincipalContext(ContextType.Domain, txtDomain.Text);
bool bResult = pc.ValidateCredentials(txtUserId.Text, txtPassword.Text);


这篇关于如何使用Windows身份验证检查用户名和密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆