Advertisement
Guest User

Untitled

a guest
May 20th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Private Sub cmdLogin_Click()
  2. On Error GoTo HanDle
  3. Dim cRet As dbErrorType, sqlStr As String, onError As dbErrorType, tSql As String
  4.    
  5.     If Dir(txtDbLoc) = "" Then
  6.         Status "Select Proper Database Location"
  7.         Exit Sub
  8.     End If
  9.     If Len(txtPass) <= 0 Then
  10.         txtPass.SetFocus
  11.         Status "Input Database Password"
  12.         Exit Sub
  13.     End If
  14.     If Len(txtKey) = 0 Then
  15.         txtKey.SetFocus
  16.         Status "Input Encryption Key"
  17.         Exit Sub
  18.     End If
  19.     If Len(txtKey) < 6 Then
  20.         txtKey.SelStart = 0
  21.         txtKey.SelLength = Len(txtKey)
  22.         txtKey.SetFocus
  23.         Exit Sub
  24.     End If
  25.    
  26.     databasePassword = txtPass
  27.     masterPassword = txtKey
  28.     databasePath = txtDbLoc
  29.    
  30.     Call sSetting("dbLocation", txtDbLoc)
  31.  
  32.    
  33.     cRet = ConnectToDB(databasePath, databasePassword)
  34.        
  35.    
  36. AUTH:
  37.        
  38.         If ADOCON.State = 1 Then
  39.        
  40.                 With ADORECORD
  41.                     If .State <> 0 Then .Close
  42.                     sqlStr = "Select * From testTable Where testUser='USERNAME'"
  43.                     Call .Open(sqlStr, ADOCON, adOpenStatic, adLockOptimistic)
  44.                     If .RecordCount = 1 Then
  45.                         If DecodeStr(!testPass, masterPassword) = "PASSWORD" Then
  46.                             Status "Logged In Sucessfully"
  47.                             txtPass = ""
  48.                             txtKey = ""
  49.                             isLoggedIn = True
  50.                             Call ShowFrame(mainFrame)
  51.                             Call PopulateList("Show &All Record's")
  52.                             Call PopulateLoginType
  53.                             Call LoadMenu
  54.                             mType(0).Checked = True
  55.                         Else
  56.                             Status "Invalid Private Key"
  57.                             txtKey.SelStart = 0
  58.                             txtKey.SelLength = Len(txtKey)
  59.                             txtKey.SetFocus
  60.                             ADOCON.Close
  61.                         End If
  62.                     Else
  63.                         MsgBox "Login Database was found Tampered" & vbNewLine & vbCrLf & _
  64.                         "Program Will Now Delete All Previous Login Table's & Create New Blank Table's" & vbCrLf & vbCrLf & _
  65.                         "Your New Encryption Key Is '" & txtKey & "', Please Note It Down To A Safe Place", vbInformation + vbOKOnly, APP_TITLE
  66.  
  67.                         On Error Resume Next
  68.                         ADOCON.Execute "DROP TABLE testTable"
  69.                         'On Error GoTo 0
  70.                        ADOCON.Execute "CREATE TABLE testTable(" & _
  71.                             "testUser   VARCHAR(50)  NOT NULL," & _
  72.                             "testPass   VARCHAR(50)  NOT NULL)"
  73.                            
  74.                         ADOCON.Execute "DROP TABLE loginDatabase"
  75.                         'On Error GoTo 0
  76.                        ADOCON.Execute "CREATE TABLE loginDatabase(" & _
  77.                             "dbType   VARCHAR(50)," & _
  78.                             "dbUsername   VARCHAR(255)," & _
  79.                             "dbPassword   VARCHAR(255))"
  80.                            
  81.                         ADOCON.Execute "INSERT INTO testTable VALUES ('USERNAME', '" & EncodeStr("PASSWORD", masterPassword) & "')"
  82.                        
  83.                         MsgBox "Login Database was found Tampered" & vbNewLine & vbCrLf & _
  84.                         "Program Will Now Delete All Previous Login Table's & Create New Blank Table's" & vbCrLf & vbCrLf & _
  85.                         "Your New Encryption Key Is '" & txtKey & "', Please Note It Down To A Safe Place", vbInformation + vbOKOnly, APP_TITLE
  86.                        
  87.                        
  88.                         On Error GoTo 0
  89.                         GoTo AUTH
  90.                     End If
  91.                 End With
  92.         Else
  93.             If cRet = 1002 Then
  94.                 Status "Database Login Failed"
  95.                 txtPass.SelStart = 0
  96.                 txtPass.SelLength = Len(txtPass)
  97.                 txtPass.SetFocus
  98.             Else
  99.                 Status "Error Connecting To Database"
  100.                 Status cRet
  101.             End If
  102.         End If
  103.  
  104.    
  105.    
  106. HanDle:
  107.  
  108.     If Err.Number = 0 Then Exit Sub
  109.     onError = GlobalError(Err.Number)
  110.     If onError = FieldNotExist Then
  111.         ADOCON.Execute "DROP TABLE testTable"
  112.         'On Error GoTo 0
  113.        ADOCON.Execute "CREATE TABLE testTable(" & _
  114.             "testUser   VARCHAR(50)  NOT NULL," & _
  115.             "testPass   VARCHAR(50)  NOT NULL)"
  116.         ADOCON.Execute "INSERT INTO testTable VALUES ('USERNAME', '" & EncodeStr("PASSWORD", masterPassword) & "')"
  117.                         MsgBox "Login Database was found Tampered" & vbNewLine & vbCrLf & _
  118.                         "Program Will Now Delete All Previous Login Table's & Create New Blank Table's" & vbCrLf & vbCrLf & _
  119.                         "Your New Encryption Key Is '" & txtKey & "', Please Note It Down To A Safe Place", vbInformation + vbOKOnly, APP_TITLE
  120.        
  121.         GoTo AUTH
  122.     ElseIf onError = AlreadyConnected Then
  123.         Resume Next
  124.     ElseIf onError = InvalidPassword Then
  125.         Status "Invalid Database Password"
  126.     ElseIf onError = NoTableFound Then
  127.         On Error Resume Next
  128.         'ADOCON.Execute "DROP TABLE testTable"
  129.        'On Error GoTo 0
  130.        ADOCON.Execute "CREATE TABLE testTable(" & _
  131.             "testUser   VARCHAR(50)  NOT NULL," & _
  132.             "testPass   VARCHAR(50)  NOT NULL)"
  133.         ADOCON.Execute "INSERT INTO testTable VALUES ('USERNAME', '" & EncodeStr("PASSWORD", masterPassword) & "')"
  134.        
  135.        
  136.                         MsgBox "Login Database was found Tampered" & vbNewLine & vbCrLf & _
  137.                         "Program Will Now Delete All Previous Login Table's & Create New Blank Table's" & vbCrLf & vbCrLf & _
  138.                         "Your New Encryption Key Is '" & txtKey & "', Please Note It Down To A Safe Place", vbInformation + vbOKOnly, APP_TITLE
  139.        
  140.         GoTo AUTH
  141.        
  142.     Else
  143.         MsgBox onError
  144.     End If
  145.     Err.Clear
  146.    
  147. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement