LOTUSSCRIPT/COM/OLE CLASSES


Examples: HashPassword method
These form events provide password protection for editing a document. The user specifies a document password by entering it in the PasswordNew and PasswordVerify fields. The PasswordVerify Exiting event hashes the plain-text password and places it in the PasswordHashed field. Thereafter upon entry of the document in Edit mode, the user must enter the password in PasswordChallange, the first field on the form. The Exiting event of PasswordChallange verifies PasswordChallange against PasswordHashed.

REM Global declarations
Dim session As NotesSession
Dim ws As NotesUIWorkspace
Dim uidoc As NotesUIDocument
%REM
Fields on this form dealing with passwords:
 PasswordHashed - Text - hidden
 PasswordChallange  - Password - first field on form
 PasswordNew - Password
 PasswordVerify - Password
%END REM

Sub Postopen(Source As Notesuidocument)
 REM Set globals
 Set session = New NotesSession
 Set ws = New NotesUIWorkspace
 Set uidoc = ws.CurrentDocument
 REM Skip PasswordChallange field if new doc or no password
 If Source.IsNewDoc Or _
 Source.FieldGetText("PasswordHashed") = "" Then
   Call Source.GotoField("Subject")
 End If
End Sub

Sub Querysave(Source As Notesuidocument, Continue As Variant)
 REM If user is in PasswordVerify, force the exit event
 If Source.CurrentField = "PasswordVerify" Then
   Call Source.GotoPrevField
 End If
 REM Remove plain-text passwords!!!
 Call Source.FieldSetText("PasswordChallange", "")
 Call Source.FieldSetText("PasswordNew", "")
 Call Source.FieldSetText("PasswordVerify", "")
 Continue = True
End Sub

REM Exiting event for PasswordChallange field
Sub Exiting(Source As Field)
 pw$ = uidoc.FieldGetText("PasswordChallange")
 pwhashed$ = uidoc.FieldGetText("PasswordHashed")
 REM Do not challange if new doc
 If uidoc.IsNewDoc Then Exit Sub
 REM Do not challange if no password
 If pwhashed$ = "" Then Exit Sub
 REM Verify user password against hashed password
 If Not session.VerifyPassword(pw$, pwhashed$) Then
   Messagebox "Password challange failed",, "Bad password"
   Call uidoc.FieldSetText("PasswordChallange", "")
   Call uidoc.GotoField("PasswordChallange")
 End If
End Sub

REM Exiting event for PasswordVerify field
Sub Exiting(Source As Field)
 pwnew$ = uidoc.FieldGetText("PasswordNew")
 pwverify$ = uidoc.FieldGetText("PasswordVerify")
 REM Remove password if new password is blank
 If pwnew$ = "" Then
   Call uidoc.FieldSetText("PasswordHashed", "")
   Exit Sub
 End If
 REM Verify new password and hash
 If pwnew$ = pwverify$ Then
   Call uidoc.FieldSetText("PasswordHashed", _
   session.HashPassword(pwnew$))
 Else
   Messagebox "Verification does not match",, "Bad password"
   Call uidoc.FieldSetText("PasswordNew", "")
   Call uidoc.FieldSetText("PasswordVerify", "")
   Call uidoc.GotoField("PasswordNew")
 End If
End Sub

See Also