在winforms项目中实现IPrincipal
我正在尝试在我当前的 winforms 项目中实现授权和身份验证。身份验证还必须与 SQL Server 2008 数据库中的用户相匹配。问题是,它是一个多用户程序,因此当添加新用户时,会创建一个数据库并将用户身份添加到数据库中。
我想知道是否可以实现 IPrincipal 和 IIdentity。到目前为止我只找到了 ASP.NET 实现。
任何人都可以给我一些关于在 winforms 应用程序中实现密码/用户 ID 安全性的最佳方法的指导吗?请记住,必须使用 SQL Server 中的数据库对其进行验证。
这意味着该用户必须存在数据库,并且他们的凭据必须正确。
I'm trying to implement Authorization and Authentication in my current winforms project. The Authentication also has to match a user in an SQL Server 2008 database. The thing is, it's a multi-user program, so when a new user is added, a database is created and the users identity added to the database.
I wondered if that is possible implementing IPrincipal and IIdentity. I've only found ASP.NET implementations so far.
Can anybody give me some guidance as to what's the best way to implement password/userid security in a winforms application? Keeping in mind that it has to be verified with a database in SQL Server.
Meaning that a database has to exist for that user, and their credentials need to be correct.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过编写实现该接口的类来实现您自己的
IPrincipal
对象。由于您将使用 Windows 以外的源来提供用户名和密码,因此您还需要编写自己的
IIdentity
实现。幸运的是,这些接口并不大。
对于您的自定义
IIdentity
,我将创建一个登录表单,尝试在 SQL 2008 数据库中查找用户名/密码组合。如果找到,您唯一关心的是如何填充该用户的“角色”,以便为界面外的IsInRole(string roleName)
方法提供功能。以下是有关如何在 Winforms 和 ASP.NET 中完成任务的详细文章的链接
更新
此外,一旦将此主体附加到当前线程(以及后续创建的线程),您还可以向代码中添加“要求”当前主体属于给定角色的属性,或者有一个名字。
这篇文章就是一个很好的示例。
You can implement your own
IPrincipal
object by writing a class that implements that interface.Since you are going to use a source other that Windows to provide username and password, you will also need to write your own
IIdentity
implementation as well.Fortunately these are not large interfaces.
For your custom
IIdentity
, I would create a Login form that attempts to find a username/password combination in the SQL 2008 database. If found, your only concern then is how to populate the "Roles" of that user to provide functionality forIsInRole(string roleName)
method off the interface.Here is a link to a detailed article on how to accomplish in both Winforms and ASP.NET
UPDATE
Also, once you attach this principal to the Current Thread (and subsequent created threads), you can also add attributes to your code that "demand" the current Principal belongs to a given role, or has a given name.
A good example of that is this article.