给准备用USBKey进行身份验证的朋友一点帮助

最近刚开始使用USBKey进行身份验证,结合ePass的开发文档,终于知道了从USBKey中读取用户的身份信息,这里贴出飞思Coffice办公系统中用来进行验证的代码,给准备使用USBKey进行身份验证的朋友一点帮助。

  1 ExpandedBlockStart.gif ContractedBlock.gif <% dot.gif @ Page language="c#" Codebehind="Index.aspx.cs" AutoEventWireup="false" Inherits="UDS.SubModule.Login.index"  %>
  2 None.gif < HTML >
  3 None.gif     < HEAD >
  4 None.gif         < title > Coffice 系统 </ title >
  5 None.gif         < meta  http-equiv ="Content-Type"  content ="text/html; charset=gb2312" >
  6 ExpandedBlockStart.gifContractedBlock.gif         < style  type ="text/css" > dot.gif
  7ExpandedSubBlockStart.gifContractedSubBlock.gif        .Vibox {dot.gif}{ BORDER-RIGHT: 0px; PADDING-RIGHT: 0px; BORDER-TOP: 0px; PADDING-LEFT: 0px; FONT-SIZE: 12px; PADDING-BOTTOM: 0px; MARGIN: 0px; BORDER-LEFT: 0px; WIDTH: 150px; COLOR: #003399; PADDING-TOP: 0px; BORDER-BOTTOM: 0px; FONT-STYLE: normal; FONT-FAMILY: "Arial", "Helvetica", "sans-serif"; HEIGHT: 18px }
  8ExpandedSubBlockStart.gifContractedSubBlock.gif        .Vibutton {dot.gif}{ BORDER-RIGHT: #006699 1px solid; PADDING-RIGHT: 1px; BORDER-TOP: #006699 1px solid; PADDING-LEFT: 1px; FONT-SIZE: 12px; PADDING-BOTTOM: 1px; MARGIN: 1px; BORDER-LEFT: #006699 1px solid; WIDTH: 60px; COLOR: #006699; PADDING-TOP: 1px; BORDER-BOTTOM: #006699 1px solid; FONT-FAMILY: "宋体"; HEIGHT: 18px; BACKGROUND-COLOR: #ffffff }
  9ExpandedSubBlockStart.gifContractedSubBlock.gif        .Vitext {dot.gif}{ FONT-SIZE: 12px; COLOR: white; FONT-FAMILY: "宋体" }
 10ExpandedSubBlockStart.gifContractedSubBlock.gif        .Mybuttona {dot.gif}{ background-image:url(../../Images/denglu.jpg); CURSOR: hand;}
 11ExpandedSubBlockStart.gifContractedSubBlock.gif        .Mybuttonb {dot.gif}{ background-image:url(../../Images/quxiao.jpg); CURSOR: hand;border: 0px solid; }
 12ExpandedBlockEnd.gif    
</ style >
 13 None.gif     </ HEAD >
 14 None.gif     < BODY  bgcolor ="#353467"  bgcolor = leftMargin="0"  topMargin ="0"  onload ='javascript:  if(this.document.all.txtUsername.value =="")  this.document.all.txtUsername.focus();else this.document.all.txtPassword.focus();' >
 15 None.gif         < span  id ="obj" ></ span >
 16 None.gif         <!-- 判断用户是否选择使用USBKey -->
 17 ExpandedBlockStart.gifContractedBlock.gif         < script  language ="javascript" > dot.gif
 18ExpandedSubBlockStart.gifContractedSubBlock.gif            function needUsbKey()dot.gif{
 19InBlock.gif            if (document.index.cb_isNeedUsbKey.checked==true)
 20ExpandedSubBlockStart.gifContractedSubBlock.gif            dot.gif{
 21InBlock.gif                obj.innerHTML="<OBJECT id='ePass' style='LEFT: 0px; TOP: 0px' height='0' width='0' classid='clsid:E740C5DF-3454-46A7-80EC-364D1ADB6CF0' name='ePass' VIEWASTEXT></OBJECT>";                        
 22ExpandedSubBlockEnd.gif            }

 23ExpandedSubBlockEnd.gif        }

 24ExpandedBlockEnd.gif        
</ script >
 25 ExpandedBlockStart.gifContractedBlock.gif         < script  language ="VBScript" > dot.gif
 26InBlock.gif
 27InBlock.gif        Dim FirstDigest
 28InBlock.gif        Dim Digest 
 29InBlock.gif        Digest= "01234567890123456"
 30InBlock.gif        dim bErr
 31InBlock.gif
 32InBlock.gif        sub ShowErr(Msg)
 33InBlock.gif            bErr = true
 34InBlock.gif            ErrMsg.innerHTML = "<input type='hidden' name='ErrMsg' Value='" & Msg & "'>"
 35InBlock.gif        End Sub
 36InBlock.gif
 37InBlock.gif        function Validate()
 38InBlock.gif            Digest = "01234567890123456"
 39InBlock.gif            On Error Resume Next
 40InBlock.gif            bErr = false
 41InBlock.gif            ePass.GetLibVersion
 42InBlock.gif            
 43InBlock.gif            If Err.number = &H1B6 Then
 44InBlock.gif
 45InBlock.gif                ShowErr "Load ePass 1000 Safe Active Control"
 46InBlock.gif                Validate = false
 47InBlock.gif                Exit function
 48InBlock.gif            Else
 49InBlock.gif                
 50InBlock.gif                ePass.OpenDevice 1""
 51InBlock.gif                
 52InBlock.gif                If Err then
 53InBlock.gif                    ShowErr "请勾选使用框,并插入USB_Key!"
 54InBlock.gif                    Validate = false
 55InBlock.gif                    ePass.CloseDevice
 56InBlock.gif                    Exit function
 57InBlock.gif                End if
 58InBlock.gif            
 59InBlock.gif                'ePass.ResetSecurityState 0
 60InBlock.gif                dim results
 61InBlock.gif                results = "01234567890123456"
 62InBlock.gif                results = ePass.GetStrProperty(700)
 63InBlock.gif
 64InBlock.gif                If Err Then
 65InBlock.gif                    ShowErr "Verify User PIN Failure!!!"
 66InBlock.gif                    Validate = false
 67InBlock.gif                    ePass.CloseDevice
 68InBlock.gif                    Exit function
 69InBlock.gif                End If
 70InBlock.gif                
 71InBlock.gif
 72InBlock.gif                If Not bErr Then
 73InBlock.gif                    ePass.ChangeDir &H300, 0"ASP_DEMO"
 74InBlock.gif                    If Err then 
 75InBlock.gif                        ShowErr "Change to demo directory"
 76InBlock.gif                        Validate = false
 77InBlock.gif                        ePass.CloseDevice
 78InBlock.gif                        Exit function
 79InBlock.gif                    End If
 80InBlock.gif                End If
 81InBlock.gif
 82InBlock.gif
 83InBlock.gif                'Open the first key file.
 84InBlock.gif                If Not bErr Then
 85InBlock.gif                    ePass.OpenFile 01
 86InBlock.gif                    If Err Then
 87InBlock.gif                        ShowErr "Open first KEY-file"
 88InBlock.gif                        Validate = false
 89InBlock.gif                        ePass.CloseDevice
 90InBlock.gif                        Exit function
 91InBlock.gif                    End If
 92InBlock.gif                
 93InBlock.gif                End If
 94InBlock.gif
 95InBlock.gif                'Do HASH-MD5-HMAC compute.
 96InBlock.gif                If Not bErr Then
 97InBlock.gif                    Digest = ePass.HashToken (12,"<%=RandData%>")
 98InBlock.gif                    If Err Then 
 99InBlock.gif                        ShowErr "HashToken compute"
100InBlock.gif                        Validate = false
101InBlock.gif                        ePass.CloseDevice
102InBlock.gif                        Exit function
103InBlock.gif                    End If
104InBlock.gif                    DigestID.innerHTML = "<input type='hidden' name='Digest' Value='" & Digest & "'>"
105InBlock.gif                    snID.innerHTML = "<input type='hidden' name='SN_SERAL' Value='" & results & "'>"
106InBlock.gif                End If        
107InBlock.gif            End If
108InBlock.gif
109InBlock.gif            ePass.CloseDevice
110InBlock.gif            
111InBlock.gif        End function
112ExpandedBlockEnd.gif    
</ script >
113 None.gif        
114 None.gif     < form  id ="index"  method ="post"  runat ="server"  onsubmit ="Validate()" >
115 None.gif         < span  id ="DigestID" ></ span >
116 None.gif         < span  id ="snID" ></ span >
117 None.gif         < span  id ="ErrMsg" ></ span >
118 None.gif         < table   bgcolor ="#353467"  cellSpacing ="0"  cellPadding ="0"  width ="100%"  height ="100%"  border ="0" >
119 None.gif                 < tr >< td  width ="443" ></ td >
120 None.gif                     < td  width ="357"  align ="center"  valign ="top" >             
121 None.gif                         < img  border ="0"  src ="../../Images/welcome.gif"  width ="224"  height ="117" >
122 None.gif                用户名: < asp:textbox  id ="txtUsername"  runat ="server"  CssClass ="Vibox" ></ asp:textbox >
123 None.gif                 < asp:requiredfieldvalidator  id ="rfvUsername"  runat ="server"  ControlToValidate ="txtUsername"  ErrorMessage ="*" ></ asp:requiredfieldvalidator >
124 None.gif                密 &nbsp; 码: < asp:textbox  id ="txtPassword"  runat ="server"  CssClass ="Vibox"  TextMode ="Password" ></ asp:textbox >
125 None.gif                 < asp:requiredfieldvalidator  id ="rfvPassword"  runat ="server"  ControlToValidate ="txtPassword"  ErrorMessage ="*" ></ asp:requiredfieldvalidator >
126 None.gif                 < asp:button  id ="btnSubmit"  BorderWidth =0  BorderStyle =None  Width ="88"  Height ="43"  runat ="server"  CssClass ="Mybuttona"  Text ="" ></ asp:button > &nbsp;
127 None.gif                 < input  class ="Mybuttonb"  style ="width=88px;height=43px"   type ="reset"  value =""  name ="Submit2" >< p >
128 None.gif                 &nbsp; < span  class ="Vitext" >< asp:CheckBox  id ="cb_isNeedUsbKey"  runat ="server"  Text ="使用USB_Key"  Height ="10px" ></ asp:CheckBox >
129 None.gif                 < asp:label  id ="lblErrorMessage"  runat ="server"  Visible ="False"  ForeColor ="Red"  Width ="128px" > 错误的用户名和口令 </ asp:label >
130 None.gif                 < p > 建议在1024*768分辨率下浏览 </ p ></ td ></ tr >
131 None.gif                 </ table >
132 None.gif         </ form >
133 None.gif     </ BODY >
134 None.gif </ HTML >


(——文中代码来自于飞思Coffice办公系统)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值