| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1340 人关注过本帖
标题:[求助] 如何登陆
只看楼主 加入收藏
terry_vicky
Rank: 1
等 级:新手上路
帖 子:70
专家分:0
注 册:2006-12-15
收藏
得分:0 

可还是不好用啊

Option Explicit

Public exePath As String

Private Sub Command1_Click()

End Sub

Private Sub cmdCancel_Click()
Unload Me
End Sub

Private Sub cmdOK_Click()

If Trim(txtUser.Text) = "" Or Trim(txtPwd.Text) = "" Then
MsgBox "用户名和密码不允许为空" & Space(5), vbExclamation + vbOKOnly, "登陆失败"
txtUser.SetFocus
Exit Sub
ElseIf InStr(1, txtUser.Text, "'") > 0 Then
MsgBox "不允许输入特殊字符" & Space(5), vbExclamation + vbOKOnly, "系统提示"
txtUser.SetFocus
SendKeys "{Home}+{End}"
Exit Sub
Else
Dim lLogin As Long
lLogin = CheckLogin(Trim(txtUser.Text), MD5(Trim(txtPwd.Text), 1))
Select Case lLogin
Case 0:
sCurUser = Trim(txtUser.Text)
Me.Hide
frmMain.Show
Unload Me

Case 1:
MsgBox "该用户不存在" & Space(5), vbInformation + vbOKOnly, "系统提示"
txtUser.SetFocus
SendKeys "{Home}+{End}"
Exit Sub

Case 2:
MsgBox "密码错误,请重新输入" & Space(5), vbExclamation + vbOKOnly, "登陆失败"
txtPwd.SetFocus
SendKeys "{Home}+{End}"
Exit Sub

Case 3:
MsgBox "登陆失败,请重新启动程序" & Space(5), vbExclamation + vbOKOnly, "登陆失败"
Unload Me

End Select
End If
End Sub
Private Function CheckLogin(Name As String, Pwd As String) As Long
On Error GoTo LoginErr

Dim Rs As Recordset
Dim Password As String

Set Rs = New Recordset

Rs.Open "Select Name,Paseword from Users where Name='" & Name & "'", cnDB, adOpenForwardOnly, adLockReadOnly

If Rs.RecordCount = 0 Then
Rs.Close
Set Rs = Nothing
CheckLogin = 1 '无次用户
Exit Function
End If

If Rs!Password <> Password Then
CheckLogin = 2
Else
CheckLogin = 0
End If

Rs.Close
Set Rs = Nothing

Exit Function
LoginErr:
'Rs.Close
Set Rs = Nothing
CheckLogin = 3

End Function


Private Sub Text1_Change()

End Sub

Private Sub Text2_Change()

End Sub

Private Sub Form_Load()
Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
Me.Hide
SystemInit
Dim bool As Boolean
End Sub

Private Sub SystemInit()
Dim Rs As Recordset
Dim conStr As String

Set cnDB = New Connection


conStr = "Provider=SQLOLEDB.1;User ID=sa;Password=;" & _
"DataSource=(local);Database=baizi;Persist Security Info=False"
cnDB.ConnectionString = conStr
cnDB.Open



If cnDB.State = adStateOpen Then





Set Rs = New Recordset
Rs.CursorLocation = adUseClient
If Rs.State <> adStateClosed Then Rs.Close


Rs.Open "Select Name,Password from Users", cnDB, adOpenForwardOnly, adLockReadOnly

If Rs.RecordCount = 0 Then
bNoUser = True
MsgBox "请先建立一个系统管理用户" & Space(5), vbInformation + vbOKOnly, "系统提示"
frmAddUser.Show
Else
bNoUser = False
Me.Show
Exit Sub
End If

Rs.Close
Set Rs = Nothing
Unload Me

Else
MsgBox "数据库连接失败,请重新启动程序" & Space(5), vbExclamation + vbOKOnly, "启动失败" '数据库连接失败则退出程序
Unload Me
End If

End Sub

2006-12-21 13:42
terry_vicky
Rank: 1
等 级:新手上路
帖 子:70
专家分:0
注 册:2006-12-15
收藏
得分:0 

可还是不好用啊

Option Explicit

Public exePath As String

Private Sub Command1_Click()

End Sub

Private Sub cmdCancel_Click()
Unload Me
End Sub

Private Sub cmdOK_Click()

If Trim(txtUser.Text) = "" Or Trim(txtPwd.Text) = "" Then
MsgBox "用户名和密码不允许为空" & Space(5), vbExclamation + vbOKOnly, "登陆失败"
txtUser.SetFocus
Exit Sub
ElseIf InStr(1, txtUser.Text, "'") > 0 Then
MsgBox "不允许输入特殊字符" & Space(5), vbExclamation + vbOKOnly, "系统提示"
txtUser.SetFocus
SendKeys "{Home}+{End}"
Exit Sub
Else
Dim lLogin As Long
lLogin = CheckLogin(Trim(txtUser.Text), MD5(Trim(txtPwd.Text), 1))
Select Case lLogin
Case 0:
sCurUser = Trim(txtUser.Text)
Me.Hide
frmMain.Show
Unload Me

Case 1:
MsgBox "该用户不存在" & Space(5), vbInformation + vbOKOnly, "系统提示"
txtUser.SetFocus
SendKeys "{Home}+{End}"
Exit Sub

Case 2:
MsgBox "密码错误,请重新输入" & Space(5), vbExclamation + vbOKOnly, "登陆失败"
txtPwd.SetFocus
SendKeys "{Home}+{End}"
Exit Sub

Case 3:
MsgBox "登陆失败,请重新启动程序" & Space(5), vbExclamation + vbOKOnly, "登陆失败"
Unload Me

End Select
End If
End Sub
Private Function CheckLogin(Name As String, Pwd As String) As Long
On Error GoTo LoginErr

Dim Rs As Recordset
Dim Password As String

Set Rs = New Recordset

Rs.Open "Select Name,Paseword from Users where Name='" & Name & "'", cnDB, adOpenForwardOnly, adLockReadOnly

If Rs.RecordCount = 0 Then
Rs.Close
Set Rs = Nothing
CheckLogin = 1 '无次用户
Exit Function
End If

If Rs!Password <> Password Then
CheckLogin = 2
Else
CheckLogin = 0
End If

Rs.Close
Set Rs = Nothing

Exit Function
LoginErr:
'Rs.Close
Set Rs = Nothing
CheckLogin = 3

End Function


Private Sub Text1_Change()

End Sub

Private Sub Text2_Change()

End Sub

Private Sub Form_Load()
Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
Me.Hide
SystemInit
Dim bool As Boolean
End Sub

Private Sub SystemInit()
Dim Rs As Recordset
Dim conStr As String

Set cnDB = New Connection


conStr = "Provider=SQLOLEDB.1;User ID=sa;Password=;" & _
"DataSource=(local);Database=baizi;Persist Security Info=False"
cnDB.ConnectionString = conStr
cnDB.Open



If cnDB.State = adStateOpen Then





Set Rs = New Recordset
Rs.CursorLocation = adUseClient
If Rs.State <> adStateClosed Then Rs.Close


Rs.Open "Select Name,Password from Users", cnDB, adOpenForwardOnly, adLockReadOnly

If Rs.RecordCount = 0 Then
bNoUser = True
MsgBox "请先建立一个系统管理用户" & Space(5), vbInformation + vbOKOnly, "系统提示"
frmAddUser.Show
Else
bNoUser = False
Me.Show
Exit Sub
End If

Rs.Close
Set Rs = Nothing
Unload Me

Else
MsgBox "数据库连接失败,请重新启动程序" & Space(5), vbExclamation + vbOKOnly, "启动失败" '数据库连接失败则退出程序
Unload Me
End If

End Sub

2006-12-21 13:43
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 
等下有时间...我帮你弄一个吧..

我的msn: myfend@
2006-12-21 13:53
terry_vicky
Rank: 1
等 级:新手上路
帖 子:70
专家分:0
注 册:2006-12-15
收藏
得分:0 
好,谢谢你啊
2006-12-21 13:56
terry_vicky
Rank: 1
等 级:新手上路
帖 子:70
专家分:0
注 册:2006-12-15
收藏
得分:0 
好,谢谢你啊
2006-12-21 14:44
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 

密码这些..我没有去加密...密码的一些..不能用户输入..我也没有去做....这些..你自己去完善....



Option Explicit

'添加引用ado2.7,你也可以添加其它版本,按实际系统而设.

'声明一个共用个Connection和RecordSet对象.
Public dbConn As ADODB.Connection
Public Rst As ADODB.Recordset

Public Enum LoginResult
LoginNormal = 0
NotUser = 1 '没有该用户
PasswordError = 2 '密码错误
NotConnect = 3 '没有连接数据库
End Enum

Public result As LoginResult

Public Sub Main()
result = ConnectDatabase()
If result = NotConnect Then
MsgBox "连接数据库失败,请重新尝试!", vbCritical, "err"
End If

frmLogin.Show
End Sub

''''''''''''''''''''''''''''''''''''''''''''''''''
'userLogin函数 : 登录
'参数:strUserName As String 传递的用户名,strPassword As String 传递的密码
'返回:没有该用户,1 ; 密码错误,2 ;登录成功,0
''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function userLogin(strUserName As String, strPassword As String) As LoginResult
On Error GoTo errHandle

If result = NotConnect Then
userLogin = NotConnect '没有连接成功
Exit Function '跳出函数
Else

Set Rst = CreateObject("ADODB.Recordset") '创建RecordSet对象实例

Dim sql As String
sql = "SELECT [User_Name],[User_Password] FROM [User_Info] WHERE [User_Name]='" & strUserName & "'"
Rst.CursorLocation = adUseClient

Rst.Open sql, dbConn, adOpenKeyset, adLockPessimistic, adCmdText
If Rst.RecordCount <= 0 Then '如果查询后,没有记录,则
Rst.Close
userLogin = NotUser
Exit Function
Else
Rst.Close '关闭
sql = "SELECT [User_Name],[User_Password] FROM [User_Info] WHERE [User_Password]='" & strPassword & "'"
Rst.Open sql, dbConn, adOpenKeyset, adLockPessimistic, adCmdText

If Rst.RecordCount <= 0 Then
Rst.Close
userLogin = PasswordError '密码错误
Exit Function
Else
Rst.Close
userLogin = LoginNormal '登录成功
Exit Function
End If
End If

End If

Exit Function
errHandle:
MsgBox Err.Description, vbCritical, "Error"
userLogin = NotConnect
End Function

'''''''''''''''''''''''''''''''''''''''''''''''''''
'ConnectDatabase函数 : 连接数据库
'参数:无
'返回:正确返回0,错误,返回3
'''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function ConnectDatabase() As LoginResult
On Error GoTo errHandle
Set dbConn = CreateObject("ADODB.Connection") '创建Connection对象实例
Dim ConString As String
ConString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" & App.Path & "\User_Login.mdb"
dbConn.ConnectionString = ConString

dbConn.Open '打开连接

ConnectDatabase = LoginNormal
Exit Function
errHandle:

ConnectDatabase = NotConnect '返回连接失败
End Function

thBmtViL.zip (10.66 KB) [求助] 如何登陆



我的msn: myfend@
2006-12-21 15:22
快速回复:[求助] 如何登陆
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032947 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved