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


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

      1<%@ Page language="c#" Codebehind="Index.aspx.cs" AutoEventWireup="false" Inherits="UDS.SubModule.Login.index" %>
      2<HTML>
      3    <HEAD>
      4        <title>Coffice 系统</title>
      5        <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
      6        <style type="text/css">
      7        .Vibox { 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 }
      8        .Vibutton { 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 }
      9        .Vitext { FONT-SIZE: 12px; COLOR: white; FONT-FAMILY: "宋体" }
     10        .Mybuttona { background-image:url(../../Images/denglu.jpg); CURSOR: hand;}
     11        .Mybuttonb { background-image:url(../../Images/quxiao.jpg); CURSOR: hand;border: 0px solid; }
     12    
    </style>
     13    </HEAD>
     14    <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        <span id="obj"></span>
     16        <!--判断用户是否选择使用USBKey-->
     17        <script language="javascript">
     18            function needUsbKey(){
     19            if (document.index.cb_isNeedUsbKey.checked==true)
     20            {
     21                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>";                        
     22            }

     23        }

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


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

    支持TerryLee的创业产品Worktile
    Worktile,新一代简单好用、体验极致的团队协同、项目管理工具,让你和你的团队随时随地一起工作。完全免费,现在就去了解一下吧。
    https://worktile.com
  • 相关阅读:
    如何做好不擅长的测试任务
    [ Python入门教程 ] Python中日志记录模块logging使用实例
    [ Python入门教程 ] Python中日期时间datetime模块使用实例
    cmd命令行窗口和文件目录资源管理器快速切换
    [ Python入门教程 ] Python中JSON模块基本使用方法
    [ PyQt入门教程 ] PyQt5中多线程模块QThread使用方法
    [ PyQt入门教程 ] PyQt5中数据表格控件QTableWidget使用方法
    设计模式目录
    我的软考架构师之路:目录(共22篇)
    算法篇:目录
  • 原文地址:https://www.cnblogs.com/Terrylee/p/246681.html
Copyright © 2020-2023  润新知