在C#中创建一个登录面板,它将获取Windows用户和密码 [英] Create a Login Panel in C# which will take windows user and password

查看:108
本文介绍了在C#中创建一个登录面板,它将获取Windows用户和密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,

我用C#创建了一个Windows窗体应用程序。

现在我想通过之前创建一个登录面板来为这个应用程序添加身份验证应用程序启动。

我想创建一个登录面板,询问用户的Windows用户名和密码,并检查他是否输入了正确的密码。

他应该以DOMAIN \USERNAME方式输入域名和用户名,然后输入密码。



有没有人创建过这样的应用程序?



请为我分享代码。



我想在应用程序运行之前创建一个登录表单。这个登录面板要求提供Windows用户名和Windows密码。



谢谢和问候,

rahoolm

Hello All,
I have created a windows form Application in C#.
Now I want to add authentication to this application by means of creating a login panel just before the application is launched.
I want to create such a login panel which ask user for his windows username and password and check whether he has entered the right password.
He should enter the Domain and Username in DOMAIN\USERNAME way and then his password.

Has anybody created such kind of application?

Please share the code for me to start.

I want to create a login form before application runs. This Login panel asks for windows username and windows password.

Thanks and Regards,
rahoolm

推荐答案

试试这个Codeproject文章,看它是否有用。



WinForm应用程序的用户登录 [ ^ ]



这个半相关提示/技巧也可能适用于您的需求:



多个后续主要表格C#应用 [ ^ ]



顺便说一句,没有sso这样的东西可以重新考虑winforms(至少不是正常情况下)术语的上下文。
Try this Codeproject article to see if it will help.

User Login For WinForm Applications[^]

And this semi-related tip/trick may also be applicable to your needs:

Multiple Subsequent "Main" Forms in C# Apps[^]

BTW, there's no such thing as "sso" with rerspect to winforms (at least not in the normal context of the term).


如果你想在应用程序上创建一个单一的登录,你不需要显示登录表格 - 这就违背了SSO的目的!



相反,你应该使用 WindowsPrincipal [ ^ ]和 WindowsIdentity [ ^ ]检索详细信息的对象当前登录用户。



例如



IF you want to create a single sign on application, you don't need to be showing a logon form - that defeats the purpose of SSO!

Instead, you should be using the WindowsPrincipal[^] and WindowsIdentity [^] objects to retrieve the details of the current logged on user.

e.g

WindowsPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
Thread.CurrentPrincipal = principal;

if (principal.IsInRole("Administrator")
{
    // Do some admin work...
}





然后,您可以根据用户组权限启用应用程序区域



You can then enable application areas based on the users group permissions


我建​​议您使用 System.DirectoryServices.AccountManagement 名称空间提供的 PrincipalContext



I would suggest you make use of PrincipalContext provided by the System.DirectoryServices.AccountManagement namespace.

using(PrincipalContext principalCntxt = new PrincipalContext(ContextType.Domain, "DOMAIN_NAME"))
{
    bool isValid = principalCntxt.ValidateCredentials("DOMAIN_NAME\\USER", "PASSWORD")
}







BR //

Harsha




BR//
Harsha


这篇关于在C#中创建一个登录面板,它将获取Windows用户和密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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