2010-01-30 68 views
0

我已經做了安全登錄,如果失敗3次程序將被終止。但是,我想創建一個將鎖定系統的安全登錄名,並且管理員將被要求登錄。如何在vb6中嘗試3次失敗後鎖定系統登錄?

這裏是我的代碼:

Dim nCnt As Integer 
Dim nCnt2 As String 

Private Sub cmdOk_Click() 

    nUsername = "username ='" & txtUsername.Text & "'" 
    npassword = txtPassword.Text 

    If nCnt < 2 Then 
     With adoLog.Recordset 
      .MoveFirst 
      .Find nUsername 
      If .EOF Then 
       MsgBox "Access Denied" & vbCrLf & "Please try again." & vbCrLf & vbCrLf & "Warning: You only have " & nCnt2 & " attempt.", vbCritical, "Terror""" 
       nCnt = nCnt + 1 
       nCnt2 = nCnt2 - 1 
       Label7.Caption = nCnt2 
       txtUsername.Text = "" 
       txtPassword.Text = "" 
       txtUsername.SetFocus 
      Else 
       If adoLog.Recordset.Fields("password").Value = npassword And adoLog.Recordset.Fields("flag").Value = 1 Then 
        Call Change_Flag 
        MsgBox "Access Granted" 
        cUser = adoLog.Recordset.Fields("name").Value 
        cPosition = adoLog.Recordset.Fields("position").Value 

        With adoHistory_Login.Recordset 
         .AddNew 
         .Fields("name").Value = cUser 
         .Fields("position").Value = cPosition 
         .Fields("time_login").Value = Time() 
         .Fields("date_login").Value = Date 
         .Fields("date_logout").Value = Date 
         .Update 
         Me.Refresh 
         frmMain.Show 
         frmMain.SetFocus 
        End With 

        Unload Me 
        txtUsername.Text = "" 
        txtPassword.Text = "" 
       Else 
        MsgBox "Access Denied" & vbCrLf & "Please try again." & vbCrLf & vbCrLf & "Warning: You only have " & nCnt2 & " attempt.", vbCritical, "Terror""" 
        nCnt = nCnt + 1 
        nCnt2 = nCnt2 - 1 
        Label7.Caption = nCnt2 
        txtUsername.Text = "" 
        txtPassword.Text = "" 
        txtUsername.SetFocus 
       End If 
      End If 
     End With 
    Else 
     Call block 
     End 
    End If 

End Sub 

Private Sub Change_Flag() 

    With adoLog.Recordset 
     .Fields("flag").Value = 0 
    End With 

End Sub 

Private Sub block() 

    MsgBox "You already used all attempt." & vbCrLf & "This will terminate the application.", vbCritical, "Terror" 

End Sub 

Private Sub Form_Initialize() 

    cmdOK.Enabled = False 
    txtPassword.Enabled = False 
    cmdRegister.Visible = False 

    If adoLog.Recordset.RecordCount <> 0 Then 
     cmdOK.Enabled = False 
     txtPassword.Enabled = False 
     txtUsername.Enabled = True 
    Else 
     cmdRegister.Visible = True 
     txtUsername.Enabled = False 
    End If 

End Sub 

Private Sub Form_Load() 

    nCnt2 = 2 
    Label7.Caption = nCnt2 

End Sub 
+0

嗯..一次嘗試讀取您的代碼,我完成了.. – 2010-01-30 15:06:48

+1

笑話,請改善您的代碼的格式 – 2010-01-30 15:07:28

回答

1

您將需要存儲的附加標誌的地方,以表明登錄被拒絕,然後嘗試登錄前檢查此標誌。您還需要存儲帳戶類型,並檢查該帳戶是否允許登錄,即使設置了此標誌。

0

你想鎖定整個PC或正在使用的用戶名嗎?

在「IsLocked」的記錄集中添加一個新列,並在3次登錄後將其設置爲true(請確保提供某種方式讓管理員將其清除)。

一旦使用用戶名,請在密碼前先檢查「IsLocked」,然後用適當的消息立即將其踢出。

此外,請確保您防止在管理員用戶名上設置IsLocked。 :)