Assign random HTTP password and e-mail notice to users

The code below uses a special view we created in our address book because we wanted to select only a certain group of users

This Content Component encountered an error

View member feedback to this tip.

Ever need to update the HTTPPassword field for all users or a selected group of users in the address book, sending them an e-mail with their new password contained within?

We needed to do this because the previous version of our application required a length of passwords of only 4, and we were strengthening the requirement for an upgrade to our application to 8.

The code below uses a special view we created in our address book because we wanted to select only a certain group of users.

It also requires a form to be added to the database. There are other ways to go about creating the random password, however, we were already using this form in our current registration application to generate passwords when a user forgot one, so I incorporated this piece from the existing application. Therefore, the code in the field on the form itself is taken from our existing application and was not written by me.

The agent will go through the address book (the current database), make a collection of the appropriate users (ours was based on the view) and loop through all of the users. For each user it generates a new password, saves the password in the person document, and sends the person a confirmation e-mail notice with the password contained within.

Agent Information
Name: Assign New Password to All Users
Shared Agent: Yes
Trigger: Manually From Actions Menu
Acts On: All documents in database

LotusScript Code:
<Options>
Option Public
Option Declare


<Declarations>
Dim sourceUserCollection As NotesDocumentCollection
Dim sourceUserView As NotesView
Dim n As Integer
Dim pwd As Variant


Sub Initialize
'The initial code gets the documents for users to be processed and 
calls the rest of the process from there. 'Handle all general errors On Error Goto ProcessError Dim session As New NotesSession Dim webnab As NotesDatabase Set webnab = session.CurrentDatabase 'A view in the address book was created that is called lupUsers
and is used to look up users Set sourceUserView = webnab.GetView("lupUsers") 'Then a collection is made based on active users. This is a
status we have personally set on our users. Set sourceUserCollection = sourceUserView.GetAllDocumentsByKey("Active", True) 'You may not want to do a collection based on a specific field,
but simply for all documents in the database in which you could use
this line instead: Set sourceUserCollection = webnab.AllDocuments For n = 1 To sourceUserCollection.count Set doc = sourceUserCollection.GetnthDocument(n) Call UpdatePassword Next Exit Sub ProcessError: 'Set status to processed, indicating the update was successfully made. Call doc.ReplaceItemValue("Status","Failure") 'Capture error message Call doc.ReplaceItemValue("ErrorMsg",Error & ", Error Number: "
& Err & ", at line number " & Erl) Call doc.Save(False, False) Exit Sub End Sub Sub UpdatePassword 'This code will first calls the code to create the password and then
set the password field. 'If it does not successfully reset the password field an error message is generated. 'It then calls the code to send the e-mail 'It creates/sets a field called status on the form so you can check
whether or not the processing was successful - 'This feature can be helpful in troubleshooting calls from users having
problems. Call CreateNewPassword 'puts the new password value in the httppassword field in their
person document Call doc.ReplaceItemValue("HTTPPassword", pwd) ret = doc.ComputeWithForm(True, False) If ret = False Then 'Set status Call doc.ReplaceItemValue("Status","Failure") 'Capture error message Call doc.ReplaceItemValue("ErrorMsg", "Could not run
ComputedWithForm on person document!") Call doc.Save(False, False) Exit Sub End If ret = doc.Save(False, False) If ret = False Then 'Set status Call doc.ReplaceItemValue("Status","Failure") 'Capture error message Call doc.ReplaceItemValue("ErrorMsg", "Person document
could not be saved!") Call doc.Save(False, False) Exit Sub End If Call sendEmail 'Set status to processed, indicating the update was successfully made. Call doc.ReplaceItemValue("status","Processed") Call doc.Save(False, False) End Sub Sub CreateNewPassword 'This script uses a form called "newpw" that contains only 1 field
(see information below*). 'It generates a random password for the user and puts the value of it
into a variable for use later. Dim docPwd As New NOTESDOCUMENT(db) Dim flag As String Set docPwd = db.CreateDocument docPwd.form = "newpw" flag =docPwd.ComputeWithForm( True, True ) Call docPwd.Save (True, True) pwd = docPwd.GetItemValue("NewPassword")(0) End Sub Sub sendEmail 'This sub will create an e-mail memo to send to the user to give them
their new, random internet password/ Dim docMemo As New NOTESDOCUMENT(db) Dim bodyField As New NOTESRICHTEXTITEM(docMemo, "Body") Dim userAddress As String Dim firstName As String 'Retrieves the user's e-mail address for sending the confirmation
e-mail with the password userAddress = doc.GetItemValue("MailAddress")(0) 'Retrieve the user's first name for addressing them in the e-mail
firstName = doc.GetItemValue("FirstName")(0) 'Set the SendTo field to the user's address Call docMemo.ReplaceItemValue("SendTo", userAddress) 'Set the subject of the e-mail Call docMemo.ReplaceItemValue("Subject","Your account information") 'Optional: The next line is optional, set the a from field
tocontrol who the responses go to (in our case, it was a help desk) Call docMemo.ReplaceItemValue("From","AccountHelp@yourdomain.com") 'Set the form Call docMemo.ReplaceItemValue("Form","Memo") 'The next lines write the body of the e-mail Call bodyField.APPENDTEXT("Dear " + firstName + ",") Call bodyField.ADDNEWLINE(2) Call bodyField.APPENDTEXT("The following is your new user password.") Call bodyField.ADDNEWLINE(2) Call bodyField.APPENDTEXT("Your new user name is: " & doc.GetItemValue("FullName")(0)) Call bodyField.ADDNEWLINE(1) 'This line adds the password previously created to the e-mail document Call bodyField.APPENDTEXT("Your temporary password is: " & pwd) Call bodyField.ADDNEWLINE(2) 'We included instructions for going to our site and having them
establish their own personal password Call bodyField.APPENDTEXT("To establish your new personal
password click here:" ) Call bodyField.ADDNEWLINE(1) Call bodyField.APPENDTEXT("website address for the registration
area to change the password was added here") Call bodyField.ADDNEWLINE(2) Call bodyField.APPENDTEXT("If you have any questions, please
contact the Help Desk:") Call bodyField.ADDNEWLINE(2) Call bodyField.APPENDTEXT("Email: AccountHelp@yourdomain.com") Call bodyField.ADDNEWLINE(2) Call bodyField.APPENDTEXT("website url here") Call docMemo.Send(False) End Sub *The form newpw contains only one field, named NewPassword, type of
text, computed when composed, with the following code: initialTemp := @Explode("b.br.bl.c.cr.cl.d.dr.f.fr.fl.g.gr.gl.h.j.k.kl.kr.l.m.n.p.pl.p
r.qu.r.s.st.sl.t.tr.v.w.y.z"; "."); numinitialTemp := @Elements(initialTemp); mid := @Explode("a.e.i.o.u.y"; "."); numMid := @Elements(mid); endTemp := @Explode("=.=.=.=.=.b.d.f.g.k.l.m.n.p.r.s.t.v.x.z"; "."); numendTemp := @Elements(endTemp); @ReplaceSubstring( @Subset(@Subset(initialTemp; @Integer(@Random * numinitialTemp)+1); -1) + @Subset(@Subset(mid; @Integer(@Random * numMid)+1); -1) + @Subset(@Subset(fin; @Integer(@Random * nendTemp)+1); -1) + @Subset(@Subset(initialTemp; @Integer(@Random * numinitialTemp)+1); -1) + @Subset(@Subset(mid; @Integer(@Random * numMid)+1); -1) + @Subset(@Subset(fin; @Integer(@Random * numendTemp)+1); -1) + @Text(@Integer(@Random * 999)); "="; "")


MEMBER FEEDBACK TO THIS TIP

We needed to create random passwords for users in the address book when we were upgrading to iNotes. I created this agent to not only create the random password but also to e-mail it to the user. The difference with this code and the script code above is that it allows you to select the users you want to set and there's no need for adding any forms, views or fields to the NAB.

Agent Settings-- Shared, Action Menu Selection -- None (so you can run @Commands). This allows me to run @Command([ToolsRefreshSelectedDocs]), which is needed. Otherwise to password is readable.


Fullname := @Subset(@Name([CN];Fullname);1);
FirstName := Firstname;

initialTemp := @Explode("b.br.bl.c.cr.cl.d.dr.f.fr.fl.g.gr.gl.h.j.k.kl.kr.l.m.n.p.
pl.pr.qu.r.s.st.sl.t.tr.v.w.y.z"; "."); numinitialTemp := @Elements(initialTemp); mid := @Explode("a.e.i.o.u.y"; "."); numMid := @Elements(mid); endTemp := @Explode("=.=.=.=.=.b.d.f.g.k.l.m.n.p.r.s.t.v.x.z"; "."); numendTemp := @Elements(endTemp); Password := @ReplaceSubstring( @Subset(@Subset(initialTemp; @Integer(@Random *
numinitialTemp)+1); -1) + @Subset(@Subset(mid; @Integer(@Random * numMid)+1); -1) + @Subset(@Subset(endTemp; @Integer(@Random * numendTemp)+1); -1) + @Subset(@Subset(initialTemp; @Integer(@Random *
numinitialTemp)+1); -1) + @Subset(@Subset(mid; @Integer(@Random * numMid)+1); -1) + @Text(@Integer(@Random * 999)); "="; ""); @SetField("HTTPPassword";Password); Pwd := HttpPassword; Body := "This e-mail contains a system-generated password for your new
Lotus iNotes account and for Lotus Sametime. Your password is " ; @MailSend(Fullname;"";"";"iNotes & Sametime Password";"";Body + pwd +
", please make a note of it."); @Command([ToolsRefreshSelectedDocs]); @All
-- Miriam V.


Do you have comments of your own? Let us know.

This was first published in March 2002

Dig deeper on Lotus Notes Domino Administration Tools

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchWinIT

Search400

  • iSeries tutorials

    Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

SearchEnterpriseLinux

SearchVirtualDataCentre.co.UK

Close