Tip

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

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


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>

This was first published in November 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

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:

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.