身份验证和角色在WPF [英] Authentication and Roles in WPF

查看:354
本文介绍了身份验证和角色在WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做WPF中的一个项目。我有一个要求用户进行身份验证,并提供平易基于角色的模块。我有一个更好的方式来实现这一目标在WPF。

I am doing a project in WPF. I got a requirement to authenticate a user and providing accessibilty for the modules based on the role. Do i have a better way to achieve this in WPF.

推荐答案

这将部分取决于你如何安全需要code是。

It will depend in part on how secure you need the code to be.

对于所有的用例,但是,使用模型 - 视图 - 视图模型模式。在每个视图模型,也许是最好放置在您的所有视图模型类的基类,包括它返回一个字符串,引发PropertyChanged事件时的安全状态变化的状态变量。

For all your use cases, though, use a Model-View-ViewModel pattern. In each ViewModel, perhaps best placed in a base class for all your ViewModel classes, include a state variable which returns a string and raises the PropertyChanged event whenever the security state changes.

相应的presentation用于该字符串的值,每个视图类,下面类似于接受的答案,这太问题的模式:

Base your presentation for each View class on the value of that string, following a pattern similar to the accepted answer to this SO question:

<一个href="http://stackoverflow.com/questions/3868164/how-to-make-a-xaml-control-with-different-view-modes#3868479">http://stackoverflow.com/questions/3868164/

答案介绍如何使用布尔值做到这一点,但你可以使用任何字符串值不是真或假,如果您的视图模型的状态变量需要两个以上的国家。

The answer describes how to do this with boolean values, but you can use any string value other than "True" or "False" if your ViewModel state variable needs more than two states.

所有.NET code,包括WPF,可以很容易地逆向工程。如果你的code需要比这更安全的,也就是说,如果你的用例假定您的用户入侵您的WPF程序,那么你将要进行模糊处理和/或加密多大的视图模型code,使用像InishTech的SLPS或Dotfuscator或任何市售产品。

All .NET code, including WPF, can be easily reverse-engineered. If your code needs to be more secure than that, that is, if your use case assumes that your users will hack your WPF program, then you will want to obfuscate and/or encrypt much of the ViewModel code, using commercially available products like InishTech's SLPS or Dotfuscator or whatever.

另外,您也可以使用相同的MVVM模式,写一个Silverlight应用程序,但我不知道,如果一个Silverlight用户有权访问该二进制文件的方式是在桌面WPF用户。

Alternatively, you could use the same MVVM pattern and write a Silverlight application, but I'm not sure if a Silverlight user has access to the binary files the way a desktop WPF user would.

这篇关于身份验证和角色在WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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