Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub cmdLogin_Click()
- On Error GoTo HanDle
- Dim cRet As dbErrorType, sqlStr As String, onError As dbErrorType, tSql As String
- If Dir(txtDbLoc) = "" Then
- Status "Select Proper Database Location"
- Exit Sub
- End If
- If Len(txtPass) <= 0 Then
- txtPass.SetFocus
- Status "Input Database Password"
- Exit Sub
- End If
- If Len(txtKey) = 0 Then
- txtKey.SetFocus
- Status "Input Encryption Key"
- Exit Sub
- End If
- If Len(txtKey) < 6 Then
- txtKey.SelStart = 0
- txtKey.SelLength = Len(txtKey)
- txtKey.SetFocus
- Exit Sub
- End If
- databasePassword = txtPass
- masterPassword = txtKey
- databasePath = txtDbLoc
- Call sSetting("dbLocation", txtDbLoc)
- cRet = ConnectToDB(databasePath, databasePassword)
- AUTH:
- If ADOCON.State = 1 Then
- With ADORECORD
- If .State <> 0 Then .Close
- sqlStr = "Select * From testTable Where testUser='USERNAME'"
- Call .Open(sqlStr, ADOCON, adOpenStatic, adLockOptimistic)
- If .RecordCount = 1 Then
- If DecodeStr(!testPass, masterPassword) = "PASSWORD" Then
- Status "Logged In Sucessfully"
- txtPass = ""
- txtKey = ""
- isLoggedIn = True
- Call ShowFrame(mainFrame)
- Call PopulateList("Show &All Record's")
- Call PopulateLoginType
- Call LoadMenu
- mType(0).Checked = True
- Else
- Status "Invalid Private Key"
- txtKey.SelStart = 0
- txtKey.SelLength = Len(txtKey)
- txtKey.SetFocus
- ADOCON.Close
- End If
- Else
- MsgBox "Login Database was found Tampered" & vbNewLine & vbCrLf & _
- "Program Will Now Delete All Previous Login Table's & Create New Blank Table's" & vbCrLf & vbCrLf & _
- "Your New Encryption Key Is '" & txtKey & "', Please Note It Down To A Safe Place", vbInformation + vbOKOnly, APP_TITLE
- On Error Resume Next
- ADOCON.Execute "DROP TABLE testTable"
- 'On Error GoTo 0
- ADOCON.Execute "CREATE TABLE testTable(" & _
- "testUser VARCHAR(50) NOT NULL," & _
- "testPass VARCHAR(50) NOT NULL)"
- ADOCON.Execute "DROP TABLE loginDatabase"
- 'On Error GoTo 0
- ADOCON.Execute "CREATE TABLE loginDatabase(" & _
- "dbType VARCHAR(50)," & _
- "dbUsername VARCHAR(255)," & _
- "dbPassword VARCHAR(255))"
- ADOCON.Execute "INSERT INTO testTable VALUES ('USERNAME', '" & EncodeStr("PASSWORD", masterPassword) & "')"
- MsgBox "Login Database was found Tampered" & vbNewLine & vbCrLf & _
- "Program Will Now Delete All Previous Login Table's & Create New Blank Table's" & vbCrLf & vbCrLf & _
- "Your New Encryption Key Is '" & txtKey & "', Please Note It Down To A Safe Place", vbInformation + vbOKOnly, APP_TITLE
- On Error GoTo 0
- GoTo AUTH
- End If
- End With
- Else
- If cRet = 1002 Then
- Status "Database Login Failed"
- txtPass.SelStart = 0
- txtPass.SelLength = Len(txtPass)
- txtPass.SetFocus
- Else
- Status "Error Connecting To Database"
- Status cRet
- End If
- End If
- HanDle:
- If Err.Number = 0 Then Exit Sub
- onError = GlobalError(Err.Number)
- If onError = FieldNotExist Then
- ADOCON.Execute "DROP TABLE testTable"
- 'On Error GoTo 0
- ADOCON.Execute "CREATE TABLE testTable(" & _
- "testUser VARCHAR(50) NOT NULL," & _
- "testPass VARCHAR(50) NOT NULL)"
- ADOCON.Execute "INSERT INTO testTable VALUES ('USERNAME', '" & EncodeStr("PASSWORD", masterPassword) & "')"
- MsgBox "Login Database was found Tampered" & vbNewLine & vbCrLf & _
- "Program Will Now Delete All Previous Login Table's & Create New Blank Table's" & vbCrLf & vbCrLf & _
- "Your New Encryption Key Is '" & txtKey & "', Please Note It Down To A Safe Place", vbInformation + vbOKOnly, APP_TITLE
- GoTo AUTH
- ElseIf onError = AlreadyConnected Then
- Resume Next
- ElseIf onError = InvalidPassword Then
- Status "Invalid Database Password"
- ElseIf onError = NoTableFound Then
- On Error Resume Next
- 'ADOCON.Execute "DROP TABLE testTable"
- 'On Error GoTo 0
- ADOCON.Execute "CREATE TABLE testTable(" & _
- "testUser VARCHAR(50) NOT NULL," & _
- "testPass VARCHAR(50) NOT NULL)"
- ADOCON.Execute "INSERT INTO testTable VALUES ('USERNAME', '" & EncodeStr("PASSWORD", masterPassword) & "')"
- MsgBox "Login Database was found Tampered" & vbNewLine & vbCrLf & _
- "Program Will Now Delete All Previous Login Table's & Create New Blank Table's" & vbCrLf & vbCrLf & _
- "Your New Encryption Key Is '" & txtKey & "', Please Note It Down To A Safe Place", vbInformation + vbOKOnly, APP_TITLE
- GoTo AUTH
- Else
- MsgBox onError
- End If
- Err.Clear
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement