您现在的位置是:首页 >

java单点登录原理 单点登录在ASP.NET上的简单实现[3]

火烧 2022-09-21 02:43:01 1054
单点登录在ASP.NET上的简单实现[3] 在代码中 Security是通过Ha h一个随机产生的数字生成的 具有不确定性 和保密性 我们可以看到 Security同时保存在Se io 中和发送给Se

单点登录在ASP.NET上的简单实现[3]  

    在代码中 Security是通过Hash一个随机产生的数字生成的 具有不确定性 和保密性 我们可以看到 Security同时保存在Session中和发送给Service 我们把这个Security当作明文 在后面我们可以看到 Security在Service经过再一次Hash后作为密文发送回Shop 如果我们将Session保存的Security经过同样的Hash方法处理后等到的字符串如果和Service返回的密文相同 我们就能够在一定程度上保证Service应答的数据是没有经过修改的 using System;using System Web;using System Security Cryptography;using System Text;namespace Amethysture SSO Shop{ public class Page : System Web UI Page {  private void CustomerValidate()  {   bool Pass = (bool) this Session[ Pass ];   if (!Pass)   {    string Security = ;    Random Seed = new Random();    Security = Seed Next( int MaxValue) ToString();    byte[] Value;    UnicodeEncoding Code = new UnicodeEncoding();    byte[] Message = Code GetBytes(Security);    SHA Managed Arithmetic = new SHA Managed();    Value = Arithmetic ComputeHash(Message);    Security = ;    foreach(byte o in Value)    {     Security += (int) o + O ;    }    this Session[ Security ] = Security;    this Session[ Url ] = this Request RawUrl;    this Response Redirect(Project Service + /Validate aspx?WebSite= + Project WebSite + &Security= + Security);   }  }  protected virtual void Initialize()  {   this Response Write( <> );   this Response Write( <head> );    this Response Write( <title>Amethysture SSO Project</title> );   this Response Write( <link rel=stylesheet type= text/css href= + project website + /Default css > );   this Response Write( </head> );   this Response Write( <body> );   this Response Write( <iframe width= height= src= + project service + /Customer aspx ></iframe> );   this Response Write( <div align= center > );   this Response Write( Amethysture SSO Shop Any Page );   this Response Write( </div> );   this Response Write( </body> );   this Response Write( </> );  }  protected override void OnInit(EventArgs e)  {   base OnInit(e);   this CustomerValidate();   this Initialize();   this Response End();  } }}

java单点登录原理 单点登录在ASP.NET上的简单实现[3]

   Service的Global cs   现在我们页面转到了Service的Validate页面 我们转过来看Service的代码 在Global中我们同样定义了四个Session变量 都和Shop的Session用处类似 WebSite是保存请求用户即时状态的站点信息 以便能在登录后返回正确的请求站点

protected void Session_Start(Object sender EventArgs e){ this Session Add( UserID ); this Session Add( Pass false); this Session Add( WebSite ); this Session Add( Security );}

lishixinzhi/Article/program/net/201311/14963  
永远跟党走
  • 如果你觉得本站很棒,可以通过扫码支付打赏哦!

    • 微信收款码
    • 支付宝收款码