如何在 Windows 窗体中实现安全组件? [英] How to implement security component in Windows Forms?

查看:44
本文介绍了如何在 Windows 窗体中实现安全组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从 ASP.NET 进入 WindowsForms 应用程序开发,我期待看到类似的控件可以使用.令我惊讶的是,我没有看到任何安全控制(登录、用户管理等)

Coming from ASP.NET into WindowsForms app development I was expecting to see the similar controls to work with. To my surprise, I didn't see any security controls (login, user management, etc.)

我是否遗漏了什么,或者我必须为应用程序实现自己的安全性(基于角色的安全性、用户管理等)?

Am I missing something, or I'd have to implement my own security for the application (role based security, user management, etc.)?

该应用程序供内部使用(10 -20 个用户),但由于敏感数据,安全性非常重要.(MSSQL Server 2005 在后端,.NET 3.5)

The application is for internal use (10 -20 users) but security is very important due to sensitive data. (MSSQL Server 2005 is in the back end, .NET 3.5)

任何信息将不胜感激.

我想我的问题是在 WinForms 中是否有类似的 ASP.NET 成员资格提供程序?"

i guess my question is "Is there an analog of ASP.NET's Membership provider in WinForms?"

经过一些谷歌搜索,我找到了这篇文章,我会给尝试一下,任何其他建议表示赞赏.

after some Googling i found this article, I'll give that a try, any other suggestions are appreciated.

推荐答案

大多数情况下,Windows 窗体应用程序在具有 Windows 域帐户的内部网络中使用.
在这种情况下,您应该使用集成安全性"连接到数据库并测试用户是否通过了

Most times a Windows Forms application is used in an internal network with Windows Domain accounts.
In this case you should use "Integrated security" to connect to the database and test if user is authenticated with

 WindowsIdentity winIdentCurrent = WindowsIdentity.GetCurrent();
 if (winIdentCurrent != null)
 {
      Console.Write("WindowsIdentity.GetCurrent(): ");
      Console.WriteLine(winIdentCurrent.Name);
      Console.Write("WindowsIdentity.GetCurrent() IsAuthenticated: ");
      Console.WriteLine(winIdentCurrent.IsAuthenticated);
      // Everything is fine, trust Windows API :-)
 }

否则
通过您自己的方法(数据库调用)验证用户/通行证

otherwise
authenticate the user/pass via your own method (db call)

  1. 使用通用连接字符串
    (不推荐)
  2. 将连接字符串的用户/密码设置为您的认证用户/通行证

并将 Thread.CurrentPrincipal 设置为您自己的 Principal 对象

AND set the Thread.CurrentPrincipal to your own Principal object

这篇关于如何在 Windows 窗体中实现安全组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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