惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 三生石上(FineUI控件)
Martin Fowler
Martin Fowler
月光博客
月光博客
AI
AI
B
Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
C
CXSECURITY Database RSS Feed - CXSecurity.com
WordPress大学
WordPress大学
GbyAI
GbyAI
L
Lohrmann on Cybersecurity
O
OpenAI News
Schneier on Security
Schneier on Security
P
Palo Alto Networks Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Troy Hunt's Blog
V2EX - 技术
V2EX - 技术
W
WeLiveSecurity
L
LINUX DO - 最新话题
人人都是产品经理
人人都是产品经理
S
Security Affairs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
A
Arctic Wolf
Recorded Future
Recorded Future
Microsoft Security Blog
Microsoft Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
G
GRAHAM CLULEY
N
Netflix TechBlog - Medium
TaoSecurity Blog
TaoSecurity Blog
C
Check Point Blog
Scott Helme
Scott Helme
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Apple Machine Learning Research
Apple Machine Learning Research
PCI Perspectives
PCI Perspectives
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Vercel News
Vercel News
The Hacker News
The Hacker News
Y
Y Combinator Blog
Latest news
Latest news
SecWiki News
SecWiki News
Hugging Face - Blog
Hugging Face - Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Google Online Security Blog
Google Online Security Blog
Webroot Blog
Webroot Blog
Google DeepMind News
Google DeepMind News
Recent Commits to openclaw:main
Recent Commits to openclaw:main
C
Cisco Blogs
博客园_首页
H
Hackread – Cybersecurity News, Data Breaches, AI and More
宝玉的分享
宝玉的分享
L
LINUX DO - 热门话题

博客园 - 9527的晃悠人生

(转)使用Visual Studio.net调试javascript最方便的方法 jsoho.com介绍 测试 学习计划 用log4net快速构建asp.net 异常日志 查找某些记录中重复的记录 竞猜系统设计文档 足球联赛竞猜管理 遍厉目录下文件和子目录 自定义下载文件名 用C#实现将html文件转换为chm文件 调试断点的条件设置 Asp.net 中 页面无刷新的做法 内容服务中的大文本处理。 关于Asp的性能优化 Insert 一个字段类型是自动增量的,又要写入变量 第三方的数据控件、分页控件 关于网络文学站的相关事宜 利用PD进行数据库建模
简单权限验证的方法
9527的晃悠人生 · 2005-06-01 · via 博客园 - 9527的晃悠人生

权限验证一直是各类大大小小的系统中核心的问题。如果一个系统权限验证都只有是否两类情况,不存在多值的情况,可以考虑用一个整数保存权限。

1。定义好各个功能在权限串中的位置,如 10001 的意义是
新增文章权限 1
修改文章权限 0
删除文章权限 0
搜索文章权限 0
发送短信权限 1

这里有一个限制,只能加,不能减少功能点,也就是在做设计时,必须仔细分析系统对应的功能点,并尽量细化,达到最小颗粒的状态。

2。以论坛为例,既有用户组权限也有版权限(栏目权限),也就是操作权限和数据权限的关系,一个用户真正的权限应该是这两组权限的交集,当然也有可能是权限优先级的问题,当各组权限出现冲突的时候,以某一组权限为标准。
得出权限交集的做法:
public static void Main()
{
int p1 = 1010;
int p2 = 0110;
//p3就是最终要保存下来的某个用户组在某个版的权限串
int p3 = MyClass.method1( p1,p2);

}
public static int method1(int p1, int p2)
{
int n1 = Convert.ToInt32(p1.ToString(), 2);
int n2 = Convert.ToInt32(p2.ToString(), 2);
int result = n1 & n2;
return Int32.Parse(Convert.ToString(result, 2));
}

3。保存权限串到Cache,系统运行时,从Cache中读取权限串进行权限验证。
如权限串10010,要判断是否有修改文章的权限,要判断权限串从左起第2位的值,
   int p1 = 10010;
    //1 有操作权限 0 无操作权限
   int r1 = int.parse( ((p1>>3)%2).ToString());

这样的做法,应该能使权限验证的代价减到最小,但不适用于有多值的权限,
特别谢谢csdn的

fancyf(凡瑞)