⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 basmain.bas

📁 程序加密算法
💻 BAS
📖 第 1 页 / 共 2 页
字号:
Attribute VB_Name = "basMain"
Option Explicit

' ***************************************************************************
' Module:        basMain.bas
'
' Description:   This module contains some of the most common routines I use
'                along with some that are just common to this application.
'
' CryptoAPI Demo using the registry
'
' This is freeware.  Since security is of the upmost these days,
' a tool such as this should assist you in protecting your data.
' This is well documented and should help you understand what is
' happening.  I have tried to give everyone credit on their code
' snippet contributions.  If you recognize something I missed, let
' me know and I will update that portion with your name and email
' address (I must have both).
'
' To begin with, I used a lot of screens to demonstrate each function.
' This is to better illustrate what is going on without getting lost in
' performing multiple functions within a single form.
'
' Next, I use a database for network security because the user would
' never have access to the directory where this database is located.
' Also, I doubt if they would recognize any of the data in it.
'
' **  Brief Overview  ***************
' Whenever a user logs onto a network, a server application is executed
' from within the login script.  This server application has the only
' access to the database as far as the user is concerned.  The user's
' logon data is extracted, manipulated and applied to the database for
' verification.  If the logon data is authenticated, the user is allowed
' onto the network.
' ***********************************
'
' This database is very limited as it is for demonstration purposes only.
'
' One of the things you could add to your code is the number of tries a
' user can make trying to remember their password. Add a couple of fields
' to the database to deny the user access for 15 minutes before being
' allowed to try again.  In other words, set a flag field in the database
' for a "1" or "0" and another field for the current timestamp.  If the
' user is locked out after three tries, a "1" is entered into the flag
' field and the system timestamp in the other.  Whenever the user attempts
' a logon, first see if there is a "1" in the flag field.  If so, then test
' to see if 15 minutes have elaspsed since the "1" was entered.  If 15
' minutes or more have elapsed then enter a "0" in the flag field and NULL
' in the timestamp field and continue processing.
'
' Using this scenario is a definite thorn in the side of individuals trying
' to gain unauthorized access to your system by way of brute force entry.
'
' If you are using local security (the user's workstation), you can
' apply these same principles for the Windows registry.  See the "Hash Test"
' and you will see where, in my opinion, a Message Digest (MDn) algorithm
' was probably used for registry entries.
'
' ===========================================================================
'    DATE      NAME / eMAIL
'              DESCRIPTION
' -----------  --------------------------------------------------------------
' 29-DEC-2000  Kenneth Ives  kenaso@home.com
'              Wrote module
' 10-JAN-2001  Kenneth Ives  kenaso@home.com
'              Converted data to byte array and then encrypt/decrypt the data.
'              For display purposes, I use a hex display because if an
'              encrypted character returned is a Null, then I would end up
'              with a null terminated string.  Everything after that null
'              would be ignored by the text box control and not displayed.
'              Therefore, when I would read from the text box to get the data
'              to decrypt, I would not have all the data.  Thanks to Haakan
'              Gustavsson for pointing me in the right direction.
'              See frmEncStrings(cmdChoice_Click)
' 18-JAN-2001  Kenneth Ives  kenaso@home.com
'              The decoded file was be one byte larger than the source.  To
'              fix this, subtract 1 from the file size to accomodate the zero
'              based array.  Fix suggested by Harbinder Gill hgill@altavista.net
'              See frmEncFiles(cmdChoice_Click)
' 20-JAN-2001  Kenneth Ives  kenaso@home.com
'              According to theory, whenever you leave a text box, the lost
'              focus event is supposed to fire.  I came upon multiple
'              instances where it did not.  It would happen when I pressed
'              the ENTER key while still inside the text box and executing
'              the command button.  I decided to move the lost focus logic
'              to the validate event and added a piece of code in the
'              keypress event to force the validate event to fire.  I could
'              had done the same with the lost focus but I had already moved
'              my code. See all password input forms.
'
'              Also found that when you use PUT to write a byte array to a
'              file, the last character is converted to a NULL.   To get
'              around this quirk, I converted the decrypted byte array to
'              a text string and then PUT it in the output file.
'              See frmEncFiles(cmdChoice_Click)
' ***************************************************************************

' ---------------------------------------------------------------------------
' Variables
' ---------------------------------------------------------------------------
  Private m_blnFoundApp            As Boolean
  Private m_intAppCount            As Integer
  Private m_strTargetTitle         As String
  Private PGM_EXE_TITLE            As String       ' Exe name w/o ext
  Public g_strVersion              As String
  
' ---------------------------------------------------------------------------
' Constants ("ThunderMain"    - VBx Development)
'           ("ThunderRT6Main" - VB6 Executable File)
' ---------------------------------------------------------------------------
  Public Const PGM_CLASS      As String = "ThunderRT6Main"
  Public Const PGM_NAME       As String = "CryptoAPI Demo"
  Public Const MAX_PATH       As Long = 260
  Public Const APP_NAME       As String = "PWDTest"
  Public Const APP_SECTION    As String = "Settings"
  Public Const MYNAME         As String = "Freeware by Kenneth Ives  kenaso@home.com"

' ---------------------------------------------------------------------------
' Declares
' ---------------------------------------------------------------------------
  ' The EnumWindows() function enumerates all top-level windows on the screen
  ' by passing the handle of each window, in turn, to an application-defined
  ' callback function. EnumWindows() continues until the last top-level window
  ' is enumerated or the callback function returns FALSE.
  Private Declare Function EnumWindows Lib "user32" _
          (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
  
  ' The GetWindowText() function copies the text of the specified window's
  ' (Parent) title bar (if it has one) into a buffer. If the specified window
  ' is a control, the text of the control is copied.
  Private Declare Function GetWindowText Lib "user32" _
          Alias "GetWindowTextA" (ByVal hWnd As Long, _
          ByVal lpString As String, ByVal cch As Long) As Long
  
  ' The GetClassName() function retrieves the name of the class to which the
  ' specified window belongs.
  Private Declare Function GetClassName Lib "user32" _
          Alias "GetClassNameA" (ByVal hWnd As Long, _
          ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
          
  ' Always close a handle if not being used
  Private Declare Function CloseHandle Lib "kernel32" _
          (ByVal hObject As Long) As Long
          
Sub Main()

' ***************************************************************************
' Routine:       Main
'
' Description:   This is a generic routine to start an application
'
' ===========================================================================
'    DATE      NAME / DESCRIPTION
' -----------  --------------------------------------------------------------
' 29-APR-2001  Kenneth Ives  kenaso@home.com
'              Wrote routine
' ***************************************************************************

' ---------------------------------------------------------------------------
' Define local variables
' ---------------------------------------------------------------------------
  ChDrive App.Path
  ChDir App.Path
  
' ---------------------------------------------------------------------------
' Initialize variables
' ---------------------------------------------------------------------------
  g_strVersion = PGM_NAME & " v" & App.Major & "." & App.Minor
  PGM_EXE_TITLE = App.EXEName
  
' ---------------------------------------------------------------------------
' See if there is another instance of this program running.  The parameter
' being passed is the name of the EXE without the extension.
' ---------------------------------------------------------------------------
  If AlreadyRunning(PGM_EXE_TITLE) Then
      End
  End If

' ---------------------------------------------------------------------------
' Get the initial settings.
' ---------------------------------------------------------------------------
  Initial_settings
  
' ---------------------------------------------------------------------------
' Load all the screens.  If these were intensive forms, I would use a splash
' screen to keep the user occupied while they loaded into memory.
' ---------------------------------------------------------------------------
  Load_All_Forms
  
End Sub

Private Sub Load_All_Forms()

' ---------------------------------------------------------------------------
' This routine will load all of my forms
' ===========================================================================
'    DATE      NAME                      DESCRIPTION
' -----------  ------------------------  ------------------------------------
' 22-FEB-2001  Kenneth Ives              Written by kenaso@home.com
' ---------------------------------------------------------------------------

' ---------------------------------------------------------------------------
' List all forms here except splash form.  Make sure the main form is last.
' ---------------------------------------------------------------------------
  Load frmAddUser
  Load frmChgPass
  Load frmDB
  Load frmDelUser
  Load frmEncFiles
  Load frmEncStrings
  Load frmHash

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -