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:

10 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.

Anonymous said...

I like play online game, I also Buy metin2 gold and Metin2 gold, the Metin2 yang is very cheap, and use the Cheap metin2 yang can buy many things, I like Cheap metin2 gold, thanks, it is very good.

I like play online game, I also Buy Perfect World Gold and Perfect World Gold, the Perfect World Silver is very cheap, and use the Perfect World money can buy many things, I like cheap Perfect World Gold, thanks, it is very good.

Adi said...

Oes Tsetnoc one of the ways in which we can learn seo besides Mengembalikan Jati Diri Bangsa. By participating in the Oes Tsetnoc or Mengembalikan Jati Diri Bangsa we can improve our seo skills. To find more information about Oest Tsetnoc please visit my Oes Tsetnoc pages. And to find more information about Mengembalikan Jati Diri Bangsa please visit my Mengembalikan Jati Diri Bangsa pages. Thank you So much.

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

jimmy choo wedges said...

|Jimmy Choo 'Buzz' Caged Sandal
|Jimmy Choo 'Clue' Glitter Slingback sandals
|Jimmy Choo 'Egypt d'Orsay Leather Pump
|Jimmy Choo Adore lace-front sandals
|Jimmy Choo Atlas strappy sandals
|Jimmy Choo Biker leather sandals

vibrams said...

The christian louboutin heels is designed for the ladies. Since the pumps was born, the ladies life become colorful. The christian louboutin evening pumps are the god's masterwork. Who invited thechristian louboutin pumps? Seldom people knew, but I think every lady would be grateful for him. Among the countless pumps, the christian louboutin peep toe is the most outstanding ones. The elegant pattern, the delicate style all mold the ladies perfect leg profile. Flowers in the spring of 2011 creeping, up from hair to clothes continue to footwear, have had a brilliant up. In such a glamor, spring and summer flowers now here. Romance is a woman's mood, exquisite flowers just right of expression in our gestures, the woman, how can we not love the romantic temperament so that they distributed the flowers do? 2011 flowers bloom will enjoy different poses! The Christian Louboutin 2011 Sandals also can adds the hright of the ladies, it bring surprise to the short lady. Especially the red sole of the louboutin heels, magic and sexy, many ladies are crazy. The red sole, the first feature of the Christian Louboutin stroe.

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.