⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logon.vb

📁 单机版餐饮服务系统,结合了SqlServer数据库
💻 VB
字号:
Imports System
Imports System.IO
Imports System.Xml
Imports System.Text
Imports System.Security
Imports System.ComponentModel
Imports System.Security.Principal
Imports System.Security.Cryptography

Namespace HZC.DinningService

    Public Class Logon

        Private m_UserName As String
        Private m_Password As String

        '// 获取或设置用户名称
        <Category("属性:用户名称")> _
        Public Property UserName() As String
            Get
                Return m_UserName
            End Get
            Set(ByVal Value As String)
                m_UserName = Value
            End Set
        End Property

        '//获取或设置用户密码
        <Category("属性:用户密码")> _
        Public Property Password() As String
            Get
                Return m_Password
            End Get
            Set(ByVal Value As String)
                m_Password = Value
            End Set
        End Property

        '// 函数 Encrypt()的代码说明
        '// 采用硬编码的加密方法进行 DES 加密
        '// 返回一个经过加密后的密码版本字符串
        Public Shared Function Encrypt(ByVal data As String) As String
            '// 注意:这下面的两个硬编码加密可以任意改动
            '// 但是,他们的范围是:0-255
            Dim desKeyValue() As Byte = {0, 27, 213, 84, 169, 97, 72, 50}
            Dim desIVValue() As Byte = {0, 49, 0, 58, 188, 92, 77, 36}
            Dim dataBytes() As Byte
            '// 因为 MemeryStream 只能处理字节数组而不能直接处理字符串
            '// 使用System.Text.ASCIIEncoding 对象将字符串转换为字节数组
            dataBytes = ASCIIEncoding.ASCII.GetBytes(data)
            Dim reader As New MemoryStream(dataBytes)
            '// 准备使用 DES 加密算法对密码进行加密
            Dim des As New DESCryptoServiceProvider
            '// 使用 CryptoStream 对象执行MemeryStream 对象中数据的加密
            Dim encryptor As New CryptoStream(reader, des.CreateEncryptor(desKeyValue, desIVValue), CryptoStreamMode.Read)
            '// 对加密的数据进行 Base64 的转换
            Dim b64 As New CryptoStream(encryptor, New ToBase64Transform, CryptoStreamMode.Read)
            Dim encryptedData() As Byte
            '// 使用另一个 MemeryStream 对象来暂存从加密流对象(CryptoStream)中读取的数据
            Dim encryptedStream As New MemoryStream
            Dim bytesRead As Integer
            ReDim encryptedData(des.BlockSize)
            '// 使用字节数组从链接的加密流对象循环读取加密的数据
            Do
                bytesRead = b64.Read(encryptedData, 0, des.BlockSize)
                If bytesRead <> 0 Then
                    encryptedStream.Write(encryptedData, 0, bytesRead)
                End If
            Loop While bytesRead > 0
            '// 根据数据的大小重新定义加密后的字节数组
            ReDim encryptedData(encryptedStream.Length - 1)
            '// 将加密流的指针置为零
            encryptedStream.Position = 0
            '// 将加密流中的数据读取到指定的缓存空间中
            encryptedStream.Read(encryptedData, 0, encryptedStream.Length)
            '// 从字节数组中输入到字符串并返回
            Return ASCIIEncoding.ASCII.GetString(encryptedData)
        End Function

        '// 函数 Authenticate的代码说明
        '// 输入参数为用户名称和已经加密的密码文本
        '// 输出参数为空或者当前用户的名称、身份和功能权限的字符串
        Public Shared Function Authenticate( _
                      ByVal mUserName As String, _
                      ByVal mPassword As String _
                      ) As String
            If mUserName Is Nothing Or mUserName = String.Empty Then
                Throw New ArgumentNullException("用户名称不能为空。")
            End If
            If mPassword Is Nothing Or mPassword = String.Empty Then
                Throw New ArgumentNullException("用户密码不能为空。")
            End If
            mPassword = Encrypt(mPassword)
            Dim sqlQueryString As String = _
            "SELECT * FROM UserInfo WHERE user_id= '" & mUserName & "'"
            Dim UserDataRow As DataRow
            Dim returnValue As String
            Try
                UserDataRow = AccessToDatabase.GetDataFromDB _
                (sqlQueryString).Tables(0).Rows(0)
                Try
                    sqlQueryString = "SELECT * FROM UserInfo WHERE user_id= '" & _
                    mUserName & "' AND user_pwd='" & mPassword & "'"
                    UserDataRow = AccessToDatabase.GetDataFromDB _
                    (sqlQueryString).Tables(0).Rows(0)
                Catch ex As Exception
                    MsgBox("帐号与密码不符,请检查您的密码,如果忘记请与管理员联系。", _
                    MsgBoxStyle.OKOnly + MsgBoxStyle.Exclamation, "登录失败")
                    Return String.Empty
                End Try
            Catch ex As Exception
                MsgBox("该账号不存在,请与管理员联系先注册。", _
                MsgBoxStyle.OKOnly + MsgBoxStyle.Exclamation, "登录失败")
                Return String.Empty
            End Try
            returnValue = CStr(UserDataRow.Item("user_id") & "|" & _
            UserDataRow.Item("user_pepdom") & "|" & _
            UserDataRow.Item("user_mod")).Trim
            Return returnValue
        End Function

    End Class

End Namespace

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -