马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
<p>1、客户为了便于维护现场设备,但同时又避免终端客户随意修改设备参数,故采用动态密码赋予终端客户临时权限,动态密码每小时自动更新一次;</p><p><img src="/upload/article/20230131/1675144983896523.jpg" title="1675144983896523.jpg" alt="用户权限.jpg"/></p><p>2、如上图所示,此用户等级为不同级别的保护,但是密码均为固定不可自动变更的;</p><p><br/></p><p><img src="/upload/article/20230131/1675145105710814.jpg" title="1675145105710814.jpg" alt="权限设置.jpg"/></p><p>3、如上图所示,对数值输入对话框进行保护,并赋予密码6等级;</p><p><br/></p><p><img src="/upload/article/20230131/1675145191701780.jpg" title="1675145191701780.jpg" alt="动态密码宏.jpg"/></p><p>4、如上图所示,通过系统寄存器的运算和赋值,将用户等级更改为动态密码,此动态密码与时间相关,并赋予计算公式,得到密码赋给SRW10118,每次需要赋予终端客户临时权限时,只需根据计算公式算出密码,并将此密码告知终端用户即可。</p><p><br/></p><p>5、代码如下:</p><p><span style="color: #008000; ">#include <macro.h></span><br/><br/><span style="color: #0000ff; font-weight: bold; ">int</span> <span style="color: #191970; font-weight: bold; ">MacroMain</span><span style="color: #006400; ">()</span><br/><span style="color: #006400; ">{</span><br/> <span style="color: #008000; ">// Here to add macro code.</span><br/> <span style="color: #ff0000; ">unsigned</span> <span style="color: #ff0000; ">short</span> data<span style="color: #006400; ">[</span><span style="color: #00008b; ">4</span><span style="color: #006400; ">]</span> <span style="color: #006400; ">=</span> <span style="color: #006400; ">{</span><span style="color: #00008b; ">0</span><span style="color: #006400; ">};</span><br/> <span style="color: #ff0000; ">unsigned</span> <span style="color: #ff0000; ">short</span> p1 <span style="color: #006400; ">=</span> <span style="color: #00008b; ">0</span><span style="color: #006400; ">;</span><span style="color: #008000; ">//年</span><br/> <span style="color: #ff0000; ">unsigned</span> <span style="color: #ff0000; ">short</span> p2 <span style="color: #006400; ">=</span> <span style="color: #00008b; ">0</span><span style="color: #006400; ">;</span><span style="color: #008000; ">//月</span><br/> <span style="color: #ff0000; ">unsigned</span> <span style="color: #ff0000; ">short</span> p3 <span style="color: #006400; ">=</span> <span style="color: #00008b; ">0</span><span style="color: #006400; ">;</span><span style="color: #008000; ">//日</span><br/> <span style="color: #ff0000; ">unsigned</span> <span style="color: #ff0000; ">short</span> p4 <span style="color: #006400; ">=</span> <span style="color: #00008b; ">0</span><span style="color: #006400; ">;</span><span style="color: #008000; ">//时</span><br/> <span style="color: #ff0000; ">unsigned</span> <span style="color: #0000ff; font-weight: bold; ">int</span> p5<span style="color: #006400; ">,</span>p6<span style="color: #006400; ">;</span><br/> <span style="color: #ff0000; ">char</span> mima1<span style="color: #006400; ">[</span><span style="color: #00008b; ">8</span><span style="color: #006400; ">]</span> <span style="color: #006400; ">=</span> <span style="color: #006400; ">{</span><span style="color: #00008b; ">0</span><span style="color: #006400; ">};</span><br/> <span style="color: #ff0000; ">char</span> mima2<span style="color: #006400; ">[</span><span style="color: #00008b; ">8</span><span style="color: #006400; ">]</span> <span style="color: #006400; ">=</span> <span style="color: #006400; ">{</span><span style="color: #00008b; ">0</span><span style="color: #006400; ">};</span><br/> <span style="color: #191970; font-weight: bold; ">GetMem</span><span style="color: #006400; ">(</span>data<span style="color: #006400; ">,</span>@时间@<span style="color: #006400; ">,</span><span style="color: #00008b; ">0</span><span style="color: #006400; ">,</span><span style="color: #00008b; ">4</span><span style="color: #006400; ">*</span><span style="color: #0000ff; font-weight: bold; ">sizeof</span><span style="color: #006400; ">(</span><span style="color: #ff0000; ">unsigned</span> <span style="color: #ff0000; ">short</span><span style="color: #006400; ">));</span><br/> p1 <span style="color: #006400; ">=</span> data<span style="color: #006400; ">[</span><span style="color: #00008b; ">0</span><span style="color: #006400; ">];</span><br/> p2 <span style="color: #006400; ">=</span> data<span style="color: #006400; ">[</span><span style="color: #00008b; ">1</span><span style="color: #006400; ">];</span><br/> p3 <span style="color: #006400; ">=</span> data<span style="color: #006400; ">[</span><span style="color: #00008b; ">2</span><span style="color: #006400; ">];</span><br/> p4 <span style="color: #006400; ">=</span> data<span style="color: #006400; ">[</span><span style="color: #00008b; ">3</span><span style="color: #006400; ">];</span><br/> p5<span style="color: #006400; ">=</span>p1<span style="color: #006400; ">*</span>p2<span style="color: #006400; ">+</span>p3<span style="color: #006400; ">*</span>p4<span style="color: #006400; ">;</span><span style="color: #008000; ">//计算公式</span><br/> p6<span style="color: #006400; ">=</span>p4<span style="color: #006400; ">*</span><span style="color: #00008b; ">3600</span><span style="color: #006400; ">+</span>p2<span style="color: #006400; ">*</span><span style="color: #00008b; ">30</span><span style="color: #006400; ">;</span><br/> mima1<span style="color: #006400; ">[</span><span style="color: #00008b; ">0</span><span style="color: #006400; ">]</span> <span style="color: #006400; ">=</span> <span style="color: #006400; ">(</span>p5<span style="color: #006400; ">/</span><span style="color: #00008b; ">10000</span><span style="color: #006400; ">+</span><span style="color: #00008b; ">0x30</span><span style="color: #006400; ">);</span><br/> mima1<span style="color: #006400; ">[</span><span style="color: #00008b; ">1</span><span style="color: #006400; ">]</span> <span style="color: #006400; ">=</span> <span style="color: #006400; ">((</span>p5<span style="color: #006400; ">%</span><span style="color: #00008b; ">10000</span><span style="color: #006400; ">/</span><span style="color: #00008b; ">1000</span><span style="color: #006400; ">)+</span><span style="color: #00008b; ">0x30</span><span style="color: #006400; ">);</span><br/> mima1<span style="color: #006400; ">[</span><span style="color: #00008b; ">2</span><span style="color: #006400; ">]</span> <span style="color: #006400; ">=</span> <span style="color: #006400; ">((</span>p5<span style="color: #006400; ">%</span><span style="color: #00008b; ">1000</span><span style="color: #006400; ">/</span><span style="color: #00008b; ">100</span><span style="color: #006400; ">)+</span><span style="color: #00008b; ">0x30</span><span style="color: #006400; ">);</span><br/> mima1<span style="color: #006400; ">[</span><span style="color: #00008b; ">3</span><span style="color: #006400; ">]</span> <span style="color: #006400; ">=</span> <span style="color: #006400; ">((</span>p5<span style="color: #006400; ">%</span><span style="color: #00008b; ">100</span><span style="color: #006400; ">/</span><span style="color: #00008b; ">10</span><span style="color: #006400; ">)+</span><span style="color: #00008b; ">0x30</span><span style="color: #006400; ">);</span><br/> mima1<span style="color: #006400; ">[</span><span style="color: #00008b; ">4</span><span style="color: #006400; ">]</span> <span style="color: #006400; ">=</span> <span style="color: #006400; ">((</span>p5<span style="color: #006400; ">%</span><span style="color: #00008b; ">10</span><span style="color: #006400; ">)+</span><span style="color: #00008b; ">0x30</span><span style="color: #006400; ">);</span><br/><br/> mima2<span style="color: #006400; ">[</span><span style="color: #00008b; ">0</span><span style="color: #006400; ">]</span> <span style="color: #006400; ">=</span> <span style="color: #006400; ">(</span>p6<span style="color: #006400; ">/</span><span style="color: #00008b; ">10000</span><span style="color: #006400; ">+</span><span style="color: #00008b; ">0x30</span><span style="color: #006400; ">);</span><br/> mima2<span style="color: #006400; ">[</span><span style="color: #00008b; ">1</span><span style="color: #006400; ">]</span> <span style="color: #006400; ">=</span> <span style="color: #006400; ">((</span>p6<span style="color: #006400; ">%</span><span style="color: #00008b; ">10000</span><span style="color: #006400; ">/</span><span style="color: #00008b; ">1000</span><span style="color: #006400; ">)+</span><span style="color: #00008b; ">0x30</span><span style="color: #006400; ">);</span><br/> mima2<span style="color: #006400; ">[</span><span style="color: #00008b; ">2</span><span style="color: #006400; ">]</span> <span style="color: #006400; ">=</span> <span style="color: #006400; ">((</span>p6<span style="color: #006400; ">%</span><span style="color: #00008b; ">1000</span><span style="color: #006400; ">/</span><span style="color: #00008b; ">100</span><span style="color: #006400; ">)+</span><span style="color: #00008b; ">0x30</span><span style="color: #006400; ">);</span><br/> mima2<span style="color: #006400; ">[</span><span style="color: #00008b; ">3</span><span style="color: #006400; ">]</span> <span style="color: #006400; ">=</span> <span style="color: #006400; ">((</span>p6<span style="color: #006400; ">%</span><span style="color: #00008b; ">100</span><span style="color: #006400; ">/</span><span style="color: #00008b; ">10</span><span style="color: #006400; ">)+</span><span style="color: #00008b; ">0x30</span><span style="color: #006400; ">);</span><br/> mima2<span style="color: #006400; ">[</span><span style="color: #00008b; ">4</span><span style="color: #006400; ">]</span> <span style="color: #006400; ">=</span> <span style="color: #006400; ">((</span>p6<span style="color: #006400; ">%</span><span style="color: #00008b; ">10</span><span style="color: #006400; ">)+</span><span style="color: #00008b; ">0x30</span><span style="color: #006400; ">);</span><br/> <span style="color: #191970; font-weight: bold; ">SetMem</span><span style="color: #006400; ">(</span>mima1<span style="color: #006400; ">,</span>@密码@<span style="color: #006400; ">,</span><span style="color: #00008b; ">0</span><span style="color: #006400; ">,</span><span style="color: #00008b; ">8</span><span style="color: #006400; ">);</span><br/> <span style="color: #191970; font-weight: bold; ">SetMem</span><span style="color: #006400; ">(</span>mima2<span style="color: #006400; ">,</span>@密码@<span style="color: #006400; ">,</span><span style="color: #00008b; ">4</span><span style="color: #006400; ">,</span><span style="color: #00008b; ">8</span><span style="color: #006400; ">);</span> <br/> <br/> <span style="color: #000080; ">return</span> <span style="color: #00008b; ">0</span><span style="color: #006400; ">;</span><br/><span style="color: #006400; ">}</span></p> |