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

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

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

搜索更多相关主题的帖子: 登陆 
2006-12-21 10:32
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 
不太清楚..代码和描述..不全..

我的msn: myfend@
2006-12-21 10:41
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 cnDB As Connection
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
Dim cnDB As Connection
Set cnDB = New Connection
' Dim bool As Boolean

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


'If bool = False Then

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

我输入用户名密码不管是错的,还是对的都走
Case "3":
MsgBox "登陆失败,请重新启动程序" & Space(5), vbExclamation + vbOKOnly, "登陆失败"
Unload Me

2006-12-21 10:49
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 

你在SystemInit过程中的cnDB要给其它过程调用的..那就应该在通用声明段中声明它...在其它的过程中..就不用再声明了..直接使用就行..


我的msn: myfend@
2006-12-21 10:55
terry_vicky
Rank: 1
等 级:新手上路
帖 子:70
专家分:0
注 册:2006-12-15
收藏
得分:0 
我现在登陆还是不成功啊
2006-12-21 11:16
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 
你改成怎么样?..再发来看看.

我的msn: myfend@
2006-12-21 11:17
terry_vicky
Rank: 1
等 级:新手上路
帖 子:70
专家分:0
注 册:2006-12-15
收藏
得分:0 
我是初学的不太知道怎么改,你能帮我看看么
2006-12-21 11:42
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 
你在SystemInit过程中的cnDB要给其它过程调用的..那就应该在通用声明段中声明它...在其它的过程中..就不用再声明了..直接使用就行..

.....你照着我说的..去改..不就行了?..

我的msn: myfend@
2006-12-21 11:44
terry_vicky
Rank: 1
等 级:新手上路
帖 子:70
专家分:0
注 册:2006-12-15
收藏
得分:0 

Option Explicit

Public bLoaded As Boolean
Public sPortList As String
Public exePath As String
Public oName As String 'orginal name
Public bNoUser As Boolean '是否第一次建立用户
Public sCurUser As String
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Public cnDB As Connection
我在模块里声明对么?

2006-12-21 13:39
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 
也可以的...

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



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

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