Home > Domino Tips > Developer > Domino > HTTP Password Setting via Notes and the Web Using @Functions, Script and JavaScript
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

DOMINO

HTTP Password Setting via Notes and the Web Using @Functions, Script and JavaScript


Michelle Mateychuk
03.13.2000
Rating: -3.67- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Finally, all the code in one place to allow users to set or change their HTTP password via Notes or the Web using @Commands, Script and JavaScript!

Brief description:
Notes form:
Button to prompt users for password(s) which uses @commands to mask entered values. Script Agent to set HTTP value in NAB.

Web Form:
Forced authentication using ?OpenForm&Login
JavaScript for input validation WebQuerySave Script Agent to set HTTP values in NAB. Computed fields for Language preferences using cookie and @DBlookups.

Quick review of requirements:
Bilingual (French and English)
Secure (enforce Notes Logoff and authentication in Notes and Web)
Initial Setup of password through Notes.
Masked password entry in Notes.
Forced password length.
Re-entered password for verification.

Notes form
A button is sent to users with the following code which composes another form with some verbiage, a button, and two fields.

Button Code
@PostedCommand([ToolsUserLogoff]);
@Command( [ToolsRunMacro] ; "(Password)" )

Fields
First_Password
Second_Password

Agents
Password Agent:
tmp := @Prompt([PASSWORD]; "HTTP Password Setup";"Enter Your Password:
(Passwords are case sensitive) The minimum number of characters required is 8.";"";"";"");
tmp2 := @Prompt([PASSWORD];"HTTP Password Setup" ;"Enter your Password again for verification: " ;"";"";"");
FIELD First_Password := tmp;
FIELD Second_Password := tmp2;
@PostedCommand([FileSave]);
@PostedCommand([FileSave]);
@Command([ToolsRunMacro];"(SETPassword)")

SETPassword (Manually from Agent list, Selected Documents)
Sub Initialize
Dim ws As New notesuiworkspace
Dim psswrd As String
Dim psswrd1 As String
Dim session As New NotesSession
Dim db1 As notesdatabase
Dim db2 As notesdatabase
Dim view As NotesView
Dim doc As notesdocument
Dim uidoc As NotesUIDocument
Set uidoc = ws.CurrentDocument
Set db1 = session.CurrentDatabase

psswrd = uidoc.FieldGetText( "First_Password" )
If Len(psswrd) < 8 Then
Msgbox("Your Password must be at least 8 characters long. Please try again.")
Exit Sub
End If

psswrd1 = uidoc.FieldGetText("Second_Password")
If psswrd <> psswrd1 Then
Msgbox("Password Mismatch. Passwords are case sensitive.")
Exit Sub
Else
Set db2 = New notesdatabase("SERVER", "names.nsf")
Set view = db2.getview("($VIMPeople)")
Set doc = view.getdocumentbykey(session.commonusername)

doc.HTTPPassword = psswrd
Call doc.computewithform(True,False)
Call doc.save(True,False)
Msgbox("Your Password has been updated.")
Call uidoc.FieldClear( "First_Password" )
Call uidoc.FieldClear( "Second_Password" )
Call uidoc.Save
Call uidoc.Close
End If

End Sub

Web Form
Force authentication on form using OpenForm&Login. UserId is pre-filled based on login uthentication.

JavaScript
<script language = javascript>

function mySubmit() {
f = document.forms[0];
var temp = new String(f.elements["New_Password"].value);
//Ensure that all fields are filled in, switch focus to offending field
if (f.elements["New_Password"].value == "") {
alert ("[ComputedNotesField]");
f.elements["New_Password"].focus();
}
else if (f.elements["New_Password2"].value == "" ) {
alert ("[ComputedNotesField]");
f.elements["New_Password2"].focus();

}
else if (f.elements["New_Password"].value != f.elements["New_Password2"].value
) {
alert ("[ComputedNotesField]");
f.elements["New_Password2"].focus();
}
else if (temp.length < 8 ) {
alert ("[ComputedNotesField]");
f.elements["New_Password"].focus();
}
else {
//all mandatory fields are completed so submit form, call agent specified in
WebQuerySave
alert ("" );
f.submit();
}

}//my submit

*LT;/script>

<center><Font size=4>
<!---->

<input type=button value="" onClick = 'mySubmit()'> </Font></center>

Notes form
A button is sent to users with the following code which composes another form with some verbiage, a button, and two fields.

Button Code
@PostedCommand([ToolsUserLogoff]);
@Command( [ToolsRunMacro] ; "(Password)" )

Fields
First_Password
Second_Password

Agents
Password Agent:
tmp := @Prompt([PASSWORD]; "HTTP Password Setup";"Enter Your Password:
(Passwords are case sensitive) The minimum number of characters required is 8.";"";"";"");
tmp2 := @Prompt([PASSWORD];"HTTP Password Setup" ;"Enter your Password again for verification: " ;"";"";"");
FIELD First_Password := tmp;
FIELD Second_Password := tmp2;
@PostedCommand([FileSave]);
@PostedCommand([FileSave]);
@Command([ToolsRunMacro];"(SETPassword)")

SETPassword (Manually from Agent list, Selected Documents)
Sub Initialize
Dim ws As New notesuiworkspace
Dim psswrd As String
Dim psswrd1 As String
Dim session As New NotesSession
Dim db1 As notesdatabase
Dim db2 As notesdatabase
Dim view As NotesView
Dim doc As notesdocument
Dim uidoc As NotesUIDocument
Set uidoc = ws.CurrentDocument
Set db1 = session.CurrentDatabase

psswrd = uidoc.FieldGetText( "First_Password" )
If Len(psswrd) < 8 Then
Msgbox("Your Password must be at least 8 characters long. Please try again." )
Exit Sub
End If

psswrd1 = uidoc.FieldGetText("Second_Password")
If psswrd <> psswrd1 Then
Msgbox("Password Mismatch. Passwords are case sensitive.")
Exit Sub
Else
Set db2 = New notesdatabase("SERVER", "names.nsf")
Set view = db2.getview("($VIMPeople)")
Set doc = iew.getdocumentbykey(session.commonusername)

doc.HTTPPassword = psswrd
Call doc.computewithform(True,False)
Call doc.save(True,False)
Msgbox("Your Password has been updated.")
Call uidoc.FieldClear( "First_Password" )
Call uidoc.FieldClear( "Second_Password" )
Call uidoc.Save
Call uidoc.Close
End If

End Sub



Code

Web Form
Force authentication on form using ?OpenForm&Login. UserId is pre-filled based on login authentication.

JavaScript
<script language = javascript>

function mySubmit() {
f = document.forms[0];
var temp = new String(f.elements["New_Password"].value);
//Ensure that all fields are filled in, switch focus to offending field if (f.elements["New_Password"].value == "") {
alert ("[ComputedNotesField]");
f.elements["New_Password"].focus();
}
else if (f.elements["New_Password2"].value == "" ) {
alert ("[ComputedNotesField]");
f.elements["New_Password2"].focus();
}
else if (f.elements["New_Password"].value != f.elements["New_Password2"].value
{
alert ("[ComputedNotesField]");
f.elements["New_Password2"].focus();
}
else if (temp.length < 8 ) {
alert ("[ComputedNotesField]");
f.elements["New_Password"].focus();
}
else {
//all mandatory fields are completed so submit form, call agent specified in WebQuerySave
alert ("[ComputedNotesField]" );
f.submit();
}

}//my submit

</script>

<center><Font size=4>
<!---->
<input type=button value="" onClick = 'mySubmit()'>
</Font></center>
<input type=button value="" onClick = 'mySubmit()'>
</Font></center>

WebQuerySave Agent (Mannual, Run Once)

Sub Initialize
Dim s As New NotesSession
Dim doc As NotesDocument

Dim Db As New NotesDatabase("","")
Dim view As notesview
Dim persondoc As notesdocument
Dim v As Variant
Dim w As Variant

' Check if person is in the NAB

On Error Goto Errhandle

Set doc = s.DocumentContext

Call db.Open("", "names.nsf")

Set view = db.getview("($VIMPeople)")

Set persondoc = view.getdocumentbykey(doc.User_ID(0))

w= Evaluate("@Password(New_Password)", doc)
Call persondoc.ReplaceItemValue("HTTPPassword", w)
Call persondoc.computewithform(True, False)
Call persondoc.save(True,False)

Print doc.path(0)
Exit Sub

Errhandle:
messageText$ = "Error" & Str(Err) & ": " & Error$

PopUpMessage$ = |<SCRIPT language="JavaScript">| & | alert("| & messageText$ &|"); | & | location.href="./" | & |</SCRIPT>| Print PopUpMessage$ ' send this to the user
Exit Sub

End Sub

Computed Notes Fields for JavaScript Alert
Lookups are done based on language values set in Cookie.
FIELD Column := Column; @DbLookup("":"No Cache"; "": "LookupDB.nsf";"Password Messages";"UserId"; Column)

N.B. Column is a field on the Web Form that looks at the language values in the Users cookie.

function mySubmit() {
f = document.forms[0];
var temp = new String(f.elements["New_Password"].value);
//Ensure that all fields are filled in, switch focus to offending field
if (f.elements["New_Password"].value == "") {
alert ("");
f.elements["New_Password"].focus();
}
else if (f.elements["New_Password2"].value == "" ) {
alert ("");
f.elements["New_Password2"].focus();
}
else if (f.elements["New_Password"].value != f.elements
["New_Password2"].value ) {
alert ("");
f.elements["New_Password2"].focus();
}
else if (temp.length < 8 ) {
alert ("");
f.elements["New_Password"].focus();
}
else {
//all mandatory fields are completed so submit form, call agent specified in WebQuerySave
alert ("" );
f.submit();
}

}//my submit

</script>

<center><Font size=4>
<!---->
<input type=button value="" onClick = 'mySubmit()'>
</Font></center>


Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Domino
Mimic Lotus Notes Domino application functionality on the Web
A single form to view and edit any Lotus Notes document
DECS and DCR external data access considerations
How to create non-scrolling Lotus Domino view headers on the Web
Disabling the 'Submit' button on a form
An easier way to update a rich text field
Results from Default Notes Search have # of responses in brackets
Lotus Notes/Domino veteran offers comprehensive list of app dev tools
Notes to XML. . .and back again
Creating thumbnail images using LS2J in LotusScript

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts