Module syspwd

    Public Const STR_MASK = "MyFunction"            '加密用字串
Public Const INT_PWD_LENGTH = '預定義密碼長度
Public GintCheckPwd As Integer
'當傳入的密碼長度大於預定義密碼長度時
'將?生一個Message Box
'以下兩個常量是該Message Box中的具體提示資訊和標題欄中的文字
Public Const STR_PWD_ERROR = "The length of password can not be greater than 10 characters !"
Public Const STR_SYSTEM_NAME = "Bogart Report System" Public Const STR_INVALID_USER = "Password is not valid !"
Public Const STR_CHANGE_PASSWORD_ERROR = "User ID is not valid !" '以下的變數的定義在正式使用時去掉 '該函數的作用是將傳入的密碼字串轉換成加密的密碼字串
'傳入的字串是用戶輸入的未經過系統加密的密碼
'傳出的資料類型是字串型,?經過系統加密後的密碼 Public Function EnPwd(ByVal strIn As String) As String
Dim intCount As Integer
Dim intPwdWord() As Integer
Dim intTemp As Integer
Dim strColumn1 As String
Dim strColumn2 As String
Dim strColumn3 As String
Dim strTemp As String
Dim intDivTemp As Integer strColumn1 = ""
strColumn2 = ""
strColumn3 = ""
intTemp =
strTemp = ""
intDivTemp = If Len(strIn) > INT_PWD_LENGTH Then
MsgBox(STR_PWD_ERROR, , STR_SYSTEM_NAME)
EnPwd = ""
Exit Function
End If
ReDim intPwdWord(INT_PWD_LENGTH) For intCount = To INT_PWD_LENGTH
If Len(STR_MASK) < INT_PWD_LENGTH Then
intTemp = intTemp +
If intTemp > Len(STR_MASK) Then
intTemp =
End If
intPwdWord(intCount) = Asc(Mid(STR_MASK, intTemp, ))
Else
intPwdWord(intCount) = Asc(Mid(STR_MASK, intCount, ))
End If
Next
For intCount = To Len(strIn)
intTemp = Asc(Mid(strIn, intCount, ))
intDivTemp = intDivTemp +
If intDivTemp > Then
intDivTemp =
End If
intTemp = intTemp * intDivTemp
intPwdWord(intCount) = intPwdWord(intCount) + intTemp
Next
For intCount = To INT_PWD_LENGTH
strTemp = CStr(intPwdWord(intCount))
If Len(strTemp) < Then
strTemp = StrDup( - Len(strTemp), "") & strTemp
End If
strColumn1 = strColumn1 & Mid(strTemp, , )
strColumn2 = strColumn2 & Mid(strTemp, , )
strColumn3 = strColumn3 & Mid(strTemp, , )
Next
EnPwd = strColumn1 & strColumn2 & strColumn3 End Function '該函數的作用是將傳入的加密的密碼字串轉換成不加密的密碼字串
'傳入的字串是經過系統加密後的密碼
'傳出的資料類型是字串型,?未經過系統加密的密碼 Public Function DePwd(ByVal strIn As String) As String
Dim intCount As Integer
Dim intTemp As Integer
Dim strTemp As String
Dim strColumn1 As String
Dim strColumn2 As String
Dim strColumn3 As String
Dim intPwdWord() As Integer
Dim intDivTemp As Integer DePwd = ""
strColumn1 = ""
strColumn2 = ""
strColumn3 = ""
intTemp =
strTemp = ""
intDivTemp = strColumn1 = Mid(strIn, , INT_PWD_LENGTH)
strColumn2 = Mid(strIn, INT_PWD_LENGTH + , INT_PWD_LENGTH)
strColumn3 = Mid(strIn, INT_PWD_LENGTH * + , INT_PWD_LENGTH)
strTemp = ""
For intCount = To INT_PWD_LENGTH
strTemp = strTemp & Mid(strColumn1, intCount, )
strTemp = strTemp & Mid(strColumn2, intCount, )
strTemp = strTemp & Mid(strColumn3, intCount, )
Next
ReDim intPwdWord(INT_PWD_LENGTH)
For intCount = To INT_PWD_LENGTH intPwdWord(intCount) = Val(Mid(strTemp, intCount * - , ))
If Len(STR_MASK) < INT_PWD_LENGTH Then
intTemp = intTemp +
If intTemp > Len(STR_MASK) Then
intTemp =
End If
intPwdWord(intCount) = intPwdWord(intCount) - Asc(Mid(STR_MASK, intTemp, ))
Else
intPwdWord(intCount) = intPwdWord(intCount) - Asc(Mid(STR_MASK, intCount, ))
End If
intDivTemp = intDivTemp +
If intDivTemp > Then
intDivTemp =
End If
intPwdWord(intCount) = intPwdWord(intCount) / intDivTemp
If intPwdWord(intCount) <> Then
DePwd = DePwd & Chr(intPwdWord(intCount)) End If
Next End Function '以下函數?檢查密碼是否有效
'傳入的第一個參數?用戶名,第二個是密碼(未加密)
'如果密碼正確,則返回True
'如果密碼不正確或該用戶不存在,則出現MsgBox後返回False
Public Function CheckPwd(ByVal strUser As String, ByVal strPassword As String) As Boolean
GintCheckPwd = GintCheckPwd +
Dim Rs As New ADODB.Recordset
Dim strSQLStmt As String CheckPwd = False
On Error GoTo DBError
If adoConn.State <> ConnectionState.Open Then
adoConn.Open()
End If strSQLStmt = "SELECT Password FROM " & g.gRptdev & "g_userid WHERE UserID='" & strUser & "'" '以下的dbconn應該改寫成統一的連庫
Rs.Open(strSQLStmt, adoConn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
If Rs.Fields().Value <> EnPwd(strPassword.ToUpper) Then
MsgBox(STR_INVALID_USER, vbCritical, STR_SYSTEM_NAME)
'If GintCheckPwd = 3 Then
' MsgBox("您已經三次登陸失敗,系統將退出", vbExclamation, STR_SYSTEM_NAME)
'End If
Exit Function
End If CheckPwd = True Exit Function
DBError:
MsgBox(STR_INVALID_USER, vbExclamation, STR_SYSTEM_NAME)
End Function '以下函數?檢查密碼是否有效
'傳入的第一個參數?用戶名,第二個是新密碼(未加密)
'如果更改成功,則返回True
'如果更改不成功(可能因?用戶不存在等原因),則出現MsgBox後返回False
Public Function ChangePwd(ByVal strUser As String, ByVal strPassword As String) As Boolean
Dim Rs As ADODB.Recordset
Dim strSQLStmt As String ChangePwd = False
On Error GoTo DBError
adoConn.BeginTrans()
strSQLStmt = "SELECT Password FROM " & g.gRptdev & "g_userid WHERE UserID='" & strUser & "'" '以下的dbconn應該改寫成統一的連庫
Rs = adoConn.Execute(strSQLStmt)
If Rs.EOF Then
MsgBox(STR_CHANGE_PASSWORD_ERROR, , STR_SYSTEM_NAME)
Rs.Close()
adoConn.RollbackTrans()
Exit Function
End If
Rs.Close()
strSQLStmt = "UPDATE " & g.gRptdev & "g_userid SET Password = '" & EnPwd(strPassword.ToUpper) & "' WHERE UserID='" & strUser & "'" adoConn.Execute(strSQLStmt)
adoConn.CommitTrans()
ChangePwd = True
Exit Function
DBError:
MsgBox(STR_CHANGE_PASSWORD_ERROR, , STR_SYSTEM_NAME)
adoConn.RollbackTrans()
End Function
End Module

Bogart SysPwd.vb的更多相关文章

  1. Bogart BogartPublic.vb

    Imports System.Data.SqlClient Imports System.Data #Region "IBogartToolbar,請勿隨便更改" Interfac ...

  2. Bogart gSub.vb

    '--------------Job No 0900408 -------------- '--DIM PART ONE ONLINE Update Order Qty '''主要新加過程名 Refr ...

  3. Bogart gData.vb

    Imports System Imports System.Data Imports System.Data.OleDb Imports Microsoft.VisualBasic Imports S ...

  4. Bogart BogartAutoCode.vb

    Imports System.Data.SqlClient Imports System.Data Public Class BogartAutoCodeDataBase Private Conn A ...

  5. Bogart gFunction.vb

    Module gFunction '其它不是常用的方法及函數 #Region " 將指定的數據格式轉換為英文格式" Public Function EnglishFormat(By ...

  6. Bogart gGrid.vb

    Namespace BogartMis.Cls Public Class gGrid '設定表格控的列標題的別名 '說明:strItem字符串的格式為"01,02,03,04,05" ...

  7. [转载]C#中MessageBox.Show用法以及VB.NET中MsgBox用法

    一.C#中MessageBox.Show用法 MessageBox.Show (String) 显示具有指定文本的消息框. 由 .NET Compact Framework 支持. MessageBo ...

  8. VB.NET设置控件和窗体的显示级别

    前言:在用VB.NET开发射频检测系统ADS时,当激活已存在的目标MDI子窗体时,被其他子窗体遮住了,导致目标MDI子窗体不能显示. 这个问题怎么解决呢?网上看到一篇帖子VB.NET设置控件和窗体的显 ...

  9. 用VB脚本批到导入字段到PowerDesigner

    在PowerDesigner使用脚本批量导入excel中记录的表结构信息,由于需要通过powerdesigner逆向工程创建一些sybase IQ的表,由于是接口数据,只有excel表,手动导入太耗时 ...

随机推荐

  1. Linux系统nat模式联网——VM是12 系统是cantos7

    >点击还原默认设置,然后确定 >选择Vmnet8,VMnet信息自动选中NAT模式 记住子网IP和子网掩码 >点击NAT设置,记住网关IP >点击DHCP.记住IP范围 > ...

  2. 代理模式及Spring AOP (二)

    一.Spring AOP   1.1 Spring AOP 底层还是用的动态代理.如果目标对象所对应的类有接口,spring就用jdk生成代理对象: 如果目标对象所对应的类没有接口,spring就用C ...

  3. HDU 2544:最短路

    最短路 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  4. HDU 1233:还是畅通工程(最小生成树)

    还是畅通工程 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  5. FZU OJ 1075 :分解素因子

    Problem 1075 分解素因子 Accept: 2161    Submit: 4126Time Limit: 1000 mSec    Memory Limit : 32768 KB  Pro ...

  6. Mac无法上网

    今天mac突然无法上网了, 家里的大部分设备, 都出现了重启后无法上网的问题, 猜测可能是dns有问题了. 于是乎, 在mac中添加了如下DNS 114.114.114.114 8.8.8.8 1.1 ...

  7. 【LGR-054】洛谷10月月赛II

    [LGR-054]洛谷10月月赛II luogu 成功咕掉Codeforces Round #517的后果就是,我\(\mbox{T4}\)依旧没有写出来.\(\mbox{GG}\) . 浏览器 \( ...

  8. 走进windows编程的世界-----消息处理函数(1)

    Win32消息机制     过程驱动:程序是依照我们预先定义好的顺序运行.每运行一步,下一步都已经依照预定的顺序 继续运行,直至程序结束.     事件驱动:程序的运行顺序是无序的.某个时间点所运行的 ...

  9. 使用gitblit搭建一个简单的局域网服务器

    使用gitblit搭建一个简单的局域网服务器 1.使用背景 现在很多使用github管理代码,但是github需要互联网的支持,而且私有的git库需要收费.有一些项目的代码不能外泄,所以,搭建一个局域 ...

  10. linux和mac使用virtualenv使用和安装

    virtualenv是python的三大神器之一,用于创建独立的python虚拟环境,多个python版本相互独立,互不影响,可以在一台电 脑上同时安装多个版本的python,而且不影响本机pytho ...