vb中做密码和账户登陆,如何判断是否正确

guanduanmei 2009-12-04 09:34:19
在vb中做密码和账户登陆时,如何检验 textbox的用户名和密码 与先前设的密码和账户一致,怎么判断 用什么指令
...全文
431 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
Qiaodows 2012-02-12
  • 打赏
  • 举报
回复
我也有
Dim cnn As ADODB.Connection
Dim i As Integer
Public Privilege As String
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_SYSCOMMAND = &H112
Private Const SC_MOVE = &HF010&
Private Const HTCAPTIO = 2

Private Sub cmdClose_Click()
Unload Me
End Sub

Private Sub cmdMin_Click()
Me.WindowState = 1
End Sub
Private Sub Command1_Click()
'检测密码
Dim Textusername As String
Dim Textpassword As String
Dim rs As ADODB.Recordset
Dim conn As DAO.Database
Dim strsql As String
Dim temp As String
Textusername = UNL.Text
Textpassword = Text1.Text
If i = 0 Then
Unload Me '限制登陆次数
Exit Sub
End If
If Me.Text1.Text = "" Or Text2.Text = "" Then
MsgBox "密码不能为空", 48, "提示"
Me.Text1.SetFocus
'账号或密码为空提示检查
Else
Set rs = New ADODB.Recordset
strsql = "select * from userinfo where UserName='" & Textusername & " ' and Password='" & Textpassword & "'"
rs.Open strsql, cnn, adOpenStatic, adLockReadOnly 'Open table "DBser"
If rs.EOF Then
MsgBox "用户名或密码错误", vbCritical, "提示"
i = i - 1
If i = 0 Then
Unload Me '限制登陆次数
Exit Sub
End If
Label3.Caption = "您还有 " & i & " 次机会"
Me.Text1 = ""
Me.Text1.SetFocus
Else
'从数据库取得privilege值 判断权限 提示用户

Privilege = rs.Fields("用户限权").Value
If rs.RecordCount = 0 Then
MsgBox "账户不存在!请检查您的数据库文件是否损坏!", vbExclamation
Exit Sub
End If
rs.Fields("Password") = Text2.Text
rs.UpdateBatch
rs.Close
Set rs = Nothing

End If
'从数据库检查用户名和密码的正确性
End If
End Sub

Private Sub Command3_Click()
'检测密码
Dim Textusername As String
Dim Textpassword As String
Dim rs As ADODB.Recordset
Dim conn As DAO.Database
Dim strsql As String
Dim temp As String
Textusername = UNL.Text
Textpassword = Text1.Text
If i = 0 Then
Unload Me '限制登陆次数
Exit Sub
End If
If Me.Text1.Text = "" Or Text2.Text = "" Then
MsgBox "密码不能为空", 48, "提示"
Me.Text1.SetFocus
'账号或密码为空提示检查
Else
Set rs = New ADODB.Recordset
strsql = "select * from userinfo where UserName='" & Textusername & " ' and Password='" & Textpassword & "'"
rs.Open strsql, cnn, adOpenStatic, adLockReadOnly 'Open table "DBser"
If rs.EOF Then
MsgBox "用户名或密码错误", vbCritical, "提示"
i = i - 1
If i = 0 Then
Unload Me '限制登陆次数
Exit Sub
End If
Label3.Caption = "您还有 " & i & " 次机会"
Me.Text1 = ""
Me.Text1.SetFocus
Else
'从数据库取得privilege值 判断权限 提示用户

Privilege = rs.Fields("用户限权").Value
If rs.RecordCount = 0 Then
MsgBox "账户不存在!请检查您的数据库文件是否损坏!", vbExclamation
Exit Sub
End If
If MsgBox("确定要这样做吗?这样会将该用户的信息与数据全部删除!", vbInformation + vbYesNo) = vbYes Then

rs.Close
Set rs = Nothing

End If
'从数据库检查用户名和密码的正确性
End If
End Sub

Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & App.Path & "\data\DATA.mdb;Jet OLEDB:Database Password=moqiaoduo2012"
Adodc1.CommandType = adCmdText
Adodc1.RecordSource = "select * from userinfo where 1<>1" 'np是access库data.mdb中的表名
Adodc1.Refresh
UNL.Clear
Adodc1.RecordSource = "select * from userinfo" 'np是access库data.mdb中的表名
Adodc1.Refresh
With Adodc1.Recordset
While Not .EOF
UNL.AddItem .Fields("UserName")
.MoveNext
Wend
End With
UNL.ListIndex = 0
'连接Access数据库
Set cnn = New ADODB.Connection
cnn.Provider = "Microsoft.Jet.OLEDB.4.0"
Dim cnnFile As String
cnnFile = "Data Source=" & App.Path & "\data\DATA.mdb;Persist Security Info=False;Jet OLEDB:Database Password=moqiaoduo2012"
cnn.Open cnnFile
'检测数据库是否链接成功

If cnn.State <> adStateOpen Then MsgBox "失败,请检查数据库文件", 48, "数据库连接"
i = 3
Label3.Caption = "您还有 " & i & " 次机会"
End Sub

Private Sub Form_Unload(Cancel As Integer)
cnn.Close
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
ReleaseCapture 'WM_SYS向窗体发送一个移动窗体命令
Call SendMessage(Me.hWnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTIO, 0) 'SC_MOVE+ HTCAPTIO表示单击左键移动窗体
End Sub

Private Sub Timer1_Timer()
Me.Cls
Me.Print vbCrLf & " 亲爱的用户:" & user.Text & ",请注意:您的用户限权为" & xq
End Sub

这个似乎保险一点
解释多余的 2009-12-10
  • 打赏
  • 举报
回复
jf
guanduanmei 2009-12-10
  • 打赏
  • 举报
回复
我做的是这个 也许可以借鉴一下的
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim selectCmd = "SELECT *FROM dlu WHERE name='" & TxtName.Text & "'And code='" & TxtCode.Text & "'"


Dim connStr As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=登陆.mdb"
Dim conn As OleDbConnection
Dim MyReader As OleDbDataReader
Dim cmd As OleDbCommand
conn = New OleDbConnection(connStr)
conn.Open()


cmd = New OleDbCommand(selectCmd, conn)


MyReader = cmd.ExecuteReader()

If MyReader.Read = True Then



Me.Hide()
Dim yourForm As New Form2
yourForm.Show()
Else
MsgBox("密码或用户名有误!请确认后在重新输入!", MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "密码检查")
End If
End Sub
Daimon 2009-12-10
  • 打赏
  • 举报
回复
       Dim DB As New DataBase
Dim DT As DataTable = DB.SelectSql("select * from user where name=" & TextBox1.Text.Trim)
If DT.Rows.Count < 0 Then
Exit Sub
End If
If DT.Rows(0).Item(1) = TextBox2.Text.Trim Then
MsgBox("", 0, "")
End If
Daimon 2009-12-09
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 terry20080416 的回复:]
cm.Connection = cn
        cm.CommandText = "select * from tablename where username='" & Trim(txtuser.Text) & "'and password='" & txtpass.Text & "'"
        cn.Open()
        cm.ExecuteNonQuery()
        cn.Close()
        Dim dat As New OleDbDataAdapter(cm)
        Dim dts As New DataSet
        dts.Tables.Clear()
        dat.Fill(dts)
        If dts.Tables(0).Rows.Count = 0 Then
            MessageBox.Show("用户和密码不正确,请重新输入!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            txtpass.Text = ""
            dat.Dispose()
            dat = Nothing
            dts.Dispose()
            dts = Nothing

            Exit Sub

        Else
    messagebox.show("成功登录","系统提示")
        End If
[/Quote]
你這個危險啊,如果我直接用' or 1=1 我就能進去了.
terry20080416 2009-12-07
  • 打赏
  • 举报
回复
cm.Connection = cn
cm.CommandText = "select * from tablename where username='" & Trim(txtuser.Text) & "'and password='" & txtpass.Text & "'"
cn.Open()
cm.ExecuteNonQuery()
cn.Close()
Dim dat As New OleDbDataAdapter(cm)
Dim dts As New DataSet
dts.Tables.Clear()
dat.Fill(dts)
If dts.Tables(0).Rows.Count = 0 Then
MessageBox.Show("用户和密码不正确,请重新输入!", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning)
txtpass.Text = ""
dat.Dispose()
dat = Nothing
dts.Dispose()
dts = Nothing

Exit Sub

Else
messagebox.show("成功登录","系统提示")
End If
liym15 2009-12-07
  • 打赏
  • 举报
回复
顶一下
qshurufa 2009-12-06
  • 打赏
  • 举报
回复
JF
wtnu200 2009-12-06
  • 打赏
  • 举报
回复
哦,啊,嗯,会了就好.顶
kuhura 2009-12-05
  • 打赏
  • 举报
回复
经验说来听听吧,感觉不像是程序的问题
appleller 2009-12-05
  • 打赏
  • 举报
回复
JF
long502481209 2009-12-05
  • 打赏
  • 举报
回复
这是入门级的问题,我早会了。但还是顶一下
ymx1121 2009-12-05
  • 打赏
  • 举报
回复
接分
guanduanmei 2009-12-04
  • 打赏
  • 举报
回复
我会了 谢谢 不会的可以问我

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧