home *** CD-ROM | disk | FTP | other *** search
- Option Explicit
- 'This program is quite simple and well documented with comments.
- 'Written by Livio Bestulic, at Point Systems, Inc (which is also me)
- 'at CIS 102370,3655. It was written because I couldn't find a simple
- 'set of Password modules/forms to insert into my programs. Its free to
- 'use this code to develop and learn from. However, I would like you to
- 'contribute $10.00 US dollars to my self interest fund if you incorporate
- 'it into your commercial/released/sold software. You can register it on
- 'CIS GO SWREG or send a check/money order to:
- 'Point Systems, Inc.
- 'PO Box 76255
- 'St Petersburg' FL 33734
- '
- 'Registered users get to ask support questions via Email and I will Email
- 'them any major updates I perform to the this base program. What do you
- 'expect for $10. See the Readme.txt for additional details etc.
- '
- 'database file stuff (is an MS Access 2.5 DB, nothing special happens
- ' in the DB, its just for storage, so you can change it to anything
- ' as long as you change the db find, read & writes to any new field names.
- Global db As database
- Global Pw As dynaset
- 'Warning, if your VB can't read the DB, you need to upgrade the included Access
- 'Jet engine supplied with old VB. Go Access on CIS and do a key word search for
- 'Compatibility Layer (from Jet 1.1 to 2.0) and Service Pack (from jet 2 to 2.5).
- 'VB 4.0 comes with Jet 2.5 for 16bit and 3.0 for 32bit.
-
- Global nResponse As Integer 'for cancel response
-
- 'variables - read and written in this order
- Global UserID As String
- Global Password As String
- Global UserName As String
- Global UserTaskLevel As String
- Global UserActivationDate As String
- Global UserExpireDate As String
-
- ' password specific constants
- Global Const EXPIRE_TERM = 90 'password expiration interval
- Global Const MAX_NAME_LENGTH = 50 ' name maximum length
- Global Const MINIMUM_ID_LENGTH = 3 'ID minimum length
- Global Const MAX_ID_LENGTH = 25 'ID maximum length
- Global Const MINIMUM_PASSWORD_LENGTH = 6 'password minimum length
- Global Const MAX_PASSWORD_LENGTH = 15 'password maximum length
- Global Const PASSWORD_FILE = "password.mdb" 'password filename
- 'important, next constant is used as encrypion key
- Global Const APP_TITTLE = "Password Program" 'Application title & encryt key
- Global Const APP_PASSWORD_REQUIRED = True 'enable password protection
- Global Const NUM_TRIES = 3 'max number of password tries before the boot!
-
- 'windows stuff
- Global Const MODAL = 1 'to show the password forms Modally ie stay on top
- Global Const MODELESS = 0 'not modal
-
- Function crypt (Action As String, Key As String, Src As String) As String
- 'E encrypts, D decrypts, Key is a unique string needed to en/decrypt (either hardcode or
- 'setup something for the user to enter. Src is the string to be en/decrypted.
-
- 'I take no credit for this Function, I picked
- 'it over a number of other methods/code available in VBPJ mag, articles etc. Its simple and I
- 'like it better than the ASCII shifting. Hex just seems a little more subtle. Replace this
- 'function with any number of similar ones out there or just write your own.
- 'from Crypt.Bas by ????.
-
- Dim count As Integer, KeyPos As Integer, KeyLen As Integer, SrcAsc As Integer
- Dim Dest As String, Offset As Integer, TmpSrcAsc, SrcPos As Integer
-
- KeyLen = Len(Key)
-
- If Action = "E" Then
- Randomize
- Offset = (Rnd * 10000 Mod 255) + 1
- Dest = Hex$(Offset)
-
- For SrcPos = 1 To Len(Src)
- SrcAsc = (Asc(Mid$(Src, SrcPos, 1)) + Offset) Mod 255
- If KeyPos < KeyLen Then KeyPos = KeyPos + 1 Else KeyPos = 1
- 'Fill Dest$ with HEX representation of Encrypted field
- 'Hex used to keep nasties such as eof or lf from mangling stream
- 'Use format$ to make Hex$ return " 0" instead of "0" when the same
- 'values are Xor'ed together (Null) - keeps placeholder for decrypt
- SrcAsc = SrcAsc Xor Asc(Mid$(Key, KeyPos, 1))
- Dest = Dest + Format$(Hex$(SrcAsc), "@@")
- Offset = SrcAsc
-
- Next
-
- ElseIf Action = "D" Then
- Offset = Val("&H" + Left$(Src, 2))
- For SrcPos = 3 To Len(Src) Step 2
- SrcAsc = Val("&H" + Trim(Mid$(Src, SrcPos, 2)))
- If KeyPos < KeyLen Then KeyPos = KeyPos + 1 Else KeyPos = 1
- TmpSrcAsc = SrcAsc Xor Asc(Mid$(Key, KeyPos, 1))
- If TmpSrcAsc <= Offset Then
- TmpSrcAsc = 255 + TmpSrcAsc - Offset
- Else
- TmpSrcAsc = TmpSrcAsc - Offset
- End If
- Dest = Dest + Chr(TmpSrcAsc)
- Offset = SrcAsc
- Next
-
- End If
- crypt = Dest
-
- End Function
-
- Sub DeletePassword (tempID As String)
-
- On Local Error GoTo DeleteError
- Screen.MousePointer = 11
-
- 'find the UserID
- Pw.FindFirst "[UserID] = '" & tempID & "'"
- If Pw.NoMatch Then ' doesn't exists
- Screen.MousePointer = 0
- Exit Sub
- End If
- 'found so delete it
- Pw.Delete
-
-
- 'say all is ok
- MsgBox "Delete was successfull.", 64, "Delete OK"
- Screen.MousePointer = 0 ' Default
- Exit Sub
-
- DeleteError:
- Beep
- MsgBox "Delete Error Occurred. " & Error, 16, " Error No. " & Err
- Exit Sub
-
-
-
-
-
-
-
- End Sub
-
- Sub FormCenterModal (frmCurrent As Form)
- frmCurrent.Left = (Screen.Width - frmCurrent.Width) / 2
- frmCurrent.Top = (Screen.Height - frmCurrent.Height) / 2
- End Sub
-
- Sub Main ()
- Dim F As String
-
- F = Dir$(app.Path & "\" & PASSWORD_FILE) 'check for file exists
- If F = "" Then 'if password file doesn't exist
- 'Password = "COMPUTER" 'password file doesn't exist.
- 'UserID = "test" 'My development backdoor or default
- 'Screen.MousePointer = 0
- 'Exit Sub
- 'use the above in development and below in final code release
- Beep 'to prevent user deleting pw file as entry point
- MsgBox "Password file could not be found or is corrupt. Call Technical Support at 1800-555-1212.", 16, "Missing or Corrupt Password File"
- End
- Else
- 'open the database (DB notes in Readme.txt)
- Set db = OpenDatabase(app.Path & "\" & PASSWORD_FILE)
- Set Pw = db.CreateDynaset("Passwords") 'table
- End If
-
-
- MainForm.Show
-
- If APP_PASSWORD_REQUIRED Then 'to disable password checking in the app.
- frmPassWord.Show MODAL
- End If
-
- End Sub
-
- Sub ReadPasswd (RAction As Integer, Rtemp As String)
- Dim temp As String
- Dim Mark As Integer, z As Integer
-
- On Local Error GoTo ReadError
-
- Screen.MousePointer = 11
- 'my back door
- Pw.MoveLast
- If Pw.RecordCount = 0 Then 'if the db is empty then this will
- UserID = "~" 'bypass the retrieval and set
- Password = "~" 'id & password to secrete backdoor
- Screen.MousePointer = 0 'enter ~ as the ID and the
- Exit Sub ' password. You can remove this but
- End If 'will need to limit deletes to prevent empting the db.
-
- If RAction = True Then
- 'find the UserID
- Pw.FindFirst "[UserID] = '" & UserID & "'"
- If Pw.NoMatch Then
- 'not found so get out of sub
- Password = Chr$(177) 'my not found character (dont want it to be blank)
- Screen.MousePointer = 0
- Exit Sub
- End If
- UserName = Pw("UserName")
- temp = Pw("Password")'the encrypted pw,level & dates
- 'was found so decrypt the string
- temp = crypt("D", APP_TITTLE, temp)
- 'seperate the parts
- 'password
- Mark = InStr(1, temp, "|")
- Password = Left(temp, Mark - 1)
- 'tasklevel
- z = InStr(Mark + 1, temp, "|")
- UserTaskLevel = Mid(temp, Mark + 1, 1)
- Mark = z
- 'activation date
- z = InStr(Mark + 1, temp, "|")
- UserActivationDate = Mid(temp, Mark + 1, z - Mark - 1)
- 'expire date
- UserExpireDate = Right(temp, Len(temp) - z)
- Else
- Pw.FindFirst "[UserID] = '" & Rtemp & "'"
- If Pw.NoMatch Then
- 'not found so get out of sub
- Rtemp = "|||"'blank
- Screen.MousePointer = 0
- Exit Sub
- End If
- Rtemp = Pw("Password")'the encrypted pw,level & dates
- Rtemp = crypt("D", APP_TITTLE, Rtemp)
- 'unparsed so it won't change your info, for display only
- End If
- Screen.MousePointer = 0
-
-
- Exit Sub
- ReadError:
- MsgBox "Read Error Occurred. " & Error, 16, " Error No. " & Err
- Resume Next
-
- End Sub
-
- Sub WritePasswd (Action As Integer, tempID As String, tempName As String, temp As String)
-
-
- On Local Error GoTo WriteError
- Screen.MousePointer = 11
-
- 'encrypt
- temp = crypt("E", APP_TITTLE, temp)
-
- If Action Then 'true is addnew
- Pw.AddNew
- Pw("UserID") = tempID
- Pw("UserName") = tempName
- Pw("Password") = temp
- Pw.Update 'update saves
- Else 'must be edit
- Pw.FindFirst "[UserID] = '" & tempID & "'"
- Pw.Edit
- Pw("UserName") = tempName
- Pw("Password") = temp
- Pw.Update 'update saves
- End If
-
- 'say all is ok
- MsgBox "Updates were successfull.", 64, "Update OK"
- Screen.MousePointer = 0 ' Default
- Exit Sub
-
- WriteError:
- Beep
- MsgBox "Write Error Occurred. " & Error, 16, " Error No. " & Err
- Exit Sub
-
-
-
-
- End Sub
-
-