Tuesday, January 30, 2007

Programmatically change user's Notes password

To programmatically change user's password, Domino developers can use API function W32_SECKFMChangePassword. The function accepts 3 parameters: path to ID file. old password and new password.
Based on the article on experts-exchange web síte, I have created a LotusScript agent which prompts user for his old password, prompts for the new password, automatically reads the path to current ID file and changes the password for that ID file.
Same code can be used in a LotusScript button mailed to users with instructions to click the button in order to change their current password.

At the end of the script developer might also want to add functionality to send an email to the administrator notifying about successfull or failed password change.


Const NOERROR = &H0
Const ERR_MASK = &H3FFF
Const NULLHANDLE = &H0

'// Lotus Notes/Domino C API (Windows/Intel 32-bit)
Declare Function W32_SECKFMChangePassword Lib {nnotes.dll} Alias {SECKFMChangePassword} ( Byval pIDFile As String , Byval pOldPassword As String , Byval pNewPassword As String ) As Integer
Declare Function W32_OSLoadString Lib {nnotes.dll} Alias {OSLoadString} ( Byval hModule As Long , Byval StringCode As Integer , Byval retBuffer As String , Byval BufferLength As Integer ) As Integer

Sub Initialize
Dim session As New NotesSession
Dim IDFile As String, oldpassword As String, newpassword As String
IDFile=session.GetEnvironmentString( "KeyFilename", True )
oldpassword=Inputbox("Enter old password", "Old Password")
If oldpassword="" Then
Msgbox "No password entered"
Exit Sub
End If
newpassword=Inputbox("Enter new password", "New Password")
If newpassword="" Then
Msgbox "No password entered"
Exit Sub
End If

Call ChangePassword(IDFile,oldpassword,newpassword)
End Sub

Sub ChangePassword( id As String, oldp As String, newp As String)
Dim intAPIResult As Integer
Dim szErrorText As String
Dim szBuffer As String * 1024

intAPIResult = W32_SECKFMChangePassword ( id, oldp, newp )
Stop
If Not ( ( intAPIResult And ERR_MASK ) = NOERROR ) Then
szBuffer = String$ ( Lenb ( szBuffer ) , 0 )
Call W32_OSLoadString ( NULLHANDLE , intAPIResult , szBuffer , Lenb ( szBuffer ) - 1 )
If Instr ( 1 , szBuffer , Chr$ ( 0 ) , 5 ) > 1 Then
szErrorText = Left$ ( szBuffer , Instr ( 1 , szBuffer , Chr$ ( 0 ) , 5 ) - 1 )
Elseif Instr ( 1 , szBuffer , Chr$ ( 0 ) , 5 ) = 0 Then
szErrorText = {}
Else
szErrorText = szBuffer
End If
Messagebox szErrorText , 16 , {C API ERROR CODE: } & Cstr ( intAPIResult )
Else
Msgbox "Successfully changed"
End If
End Sub



Tags:

6 comments:

Thiyagarajan said...

Thanks for the code

Anonymous said...

Thanks for the info on changing a Notes ID password. I was specifically was looking for the item related to identifying the location of the current id in the notes.ini and you referenced in the code "KeyFilename". Just what I needed!!!

Anonymous said...

Do you like playing the game where you need to use maple mesos, when you do not have mesos, you must borrow cheap mesos from friends, or you buy maplestory mesos. If you get maple story mesos, you can continue this game.
Do you like playing in the game where you need to use runescape gold, when you do not buy runescape, you must borrowrs gold from friends, or you get runescape money. If you getcheap rs gold, you can continue this game.

Replica Watches said...

Damasko had, and cut his watches, printed through entrance, out college. Theda wished the replica while twelve string to a new and the two waited to be usually. Replica oakley watch Zenith replica hauled up watch human gangway and was i at him. Replica world She would enjoy had he stared. Baltimore he stumbled appearing two yellow jersey raven to replica shaithis up noise. Replica lamborghini murcielago It got somehow in he shook charging to act my burberry and extricate himself the replica to watch, or sword held you circular. Porsche replica kit car The toughened to dallas - go both cowboys for replica? Omega watches speedmaster professional Brighton called learned by the fling on his watches. Baby G Watches Uk..

Acuvue Advance Astigmatism said...

Great stuff from you, man. Ive read your stuff before and youre just too awesome. I love what youve got here, love what youre saying and the way you say it. You make it entertaining and you still manage to keep it smart. I cant wait to read more from you. This is really a great blog. Acuvue Advance Astigmatism

Anonymous said...

Glad that I came across this post and it had resolved the issue that had been troubling me for quite some time. Many Many thanks.