我弄了好久了,还是写不出来哦
请编写一个程序模仿一个登录的过程。要求如下:
(1)开始时显示一个“登录”对话框让用户输入账号和口令。
(2)单击“确定”按钮时验证口令的正确性,如果正确则关闭“登录”对话框并打开程序的主窗口,否则应该做出提示。
(3)最多只允许用户输入3次口令。
(4)允许用户取消登录。
(5)成功登录后在主窗口的标题栏中添加显示用户的账号和登录的日期和时间。
急用..........
这是我半年前写的,与你想要的程序功能差不多,没加注释不好意思,你在自己改一改吧,希望对你有启发
Dim m_m
Private tc As Integer
Private tc1 As Integer
Private a As Integer
Dim t1, t2 As Integer
Option Explicit
Private Sub Combo1_Click()
If Combo1.ListIndex <> -1 Then
Text1.Enabled = True
Text1.SetFocus
Text1.BackColor = &H80000005
Command1.Enabled = True
Timer3.Enabled = False
Else
Label2.Caption = "请选择一个用户"
End If
m_m = Combo1.Text
End Sub
Private Sub Command1_Click()
If a < 2 Then
If (Combo1.ListIndex = 0 And Text1.Text = "3698") Or (Combo1.ListIndex = 1 And Text1.Text = "1228") Then
Unload srkl
Load Form1
Form1.Show
Form1.Label20.Caption = m_m
Else
Label2.Visible = True
Label2.Caption = "口令错误,重新输入!!"
Text1.Text = ""
Text1.SetFocus
End If
Else
Command1.Enabled = False
tc = 1
tc1 = 11
Text1.Locked = True
Timer2.Enabled = True
Text1.Alignment = 2
Text1.ForeColor = RGB(255, 0, 0)
Text1.Text = ""
End If
a = a + 1
Label4.Caption = 3 - a
If a = 3 Then
Label2.Visible = True
Label2.Caption = "你是非法用户,不能使用此程序!!"
Text1.PasswordChar = ""
Text1.SetFocus
End If
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Form_Activate()
Load srkl
Combo1.SetFocus
Timer3.Enabled = True
t1 = Second(Time)
t2 = t1 + 5
End Sub
Private Sub Timer1_Timer()
Label6.Caption = "时钟 " & Time '& ":" & Right(Timer, 2)
End Sub
Private Sub Timer2_Timer()
Text1.Text = tc1 - tc & "秒后自动退出"
tc = tc + 1
If tc1 - tc = -1 Then End
End Sub
Private Sub Timer3_Timer()
Dim t3 As Integer
t3 = t2 - t1
If t3 = 5 Then
Label8.Visible = False
Label9.Visible = False
Label10.Visible = False
Label11.Visible = False
Label12.Visible = True
End If
If t3 = 4 Then
Label8.Visible = False
Label9.Visible = False
Label10.Visible = False
Label11.Visible = True
Label12.Visible = False
End If
If t3 = 3 Then
Label8.Visible = False
Label9.Visible = False
Label10.Visible = True
Label11.Visible = False
Label12.Visible = False
End If
If t3 = 2 Then
Label8.Visible = False
Label9.Visible = True
Label10.Visible = False
Label11.Visible = False
Label12.Visible = False
End If
If t3 = 1 Then
Label8.Visible = True
Label9.Visible = False
Label10.Visible = False
Label11.Visible = False
Label12.Visible = False
t2 = t1 + 5
End If
t2 = t2 - 1
End Sub
我大概的写了一下...你自己去完善吧...数据库中的密码最好是先加密.....可以自己写一个算法来对密码加密..这样比较安全..
基本思路如下...
Option Explicit
Private Lobool As Boolean
Private Conn As ADODB.Connection
Private Rst As ADODB.Recordset
Private LoginingNumber As Integer
Private Sub Command1_Click()
If Text1.Text = "" Or Text2.Text = "" Or Text3.Text = "" Then
MsgBox "请输入内容"
Exit Sub
End If
Call SettextBox(True)
If Lobool = False Then
Exit Sub
End If
Dim sql As String
sql = "Select User_Name,User_Password From User_Login Where User_Name ='" & Text1.Text & "' And User_Password = '" & Text2.Text & "'"
Set Rst = Conn.Execute(sql)
If (Rst.RecordCount > 0) Then
Rst.Close
MsgBox "登录成功"
Form2.Show
Else
Rst.Close
MsgBox "登录失败"
LoginingNumber = LoginingNumber + 1
End If
If (LoginingNumber > 3) Then
MsgBox "你没有使用权了,请与管理员联系"
End
End If
End Sub
Private Sub SettextBox(ByVal txtbool As Boolean)
If txtbool Then
If (Text2.Text <> Text3.Text) Then
MsgBox "两次密码不相同.请重新输入密码."
Lobool = False
Else
Lobool = True
End If
Else
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End If
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Form_Load()
Call SettextBox(False)
Dim ConStr As String
ConStr = "Provider=Microsoft.Jet.OleDb.4.0;Data Source =" & App.Path & "\Login.mdb"
Set Conn = CreateObject("ADODB.Connection")
With Conn
.ConnectionString = ConStr
.CursorLocation = adUseClient
.Open
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set Conn = Nothing
Set Rst = Nothing
End Sub