Share via


How to: Set Initial Passwords in Sun and Netscape Directory Servers

When you add a user to Sun and Netscape directory servers, you can set an initial password for the new user. To set the initial password, set the userPassword attribute to a value. You can set the initial password of a user by implementing the Provision method of your management agent rules extension.

The following examples show how to set the initial password of a user in Sun and Netscape directory servers.

Public Sub Provision(ByVal mventry As MVEntry) _
Implements IMVSynchronization.Provision

    Dim ManagementAgent As ConnectedMA
    Dim Connectors As Integer
    Dim dn As ReferenceValue
    Dim container As String
    Dim rdn As String

    ManagementAgent = mventry.ConnectedMAs("iPlanet MA")
    Connectors = ManagementAgent.Connectors.Count

    If 0 = Connectors Then
        rdn = "CN=" & mventry("cn").Value
        container = "ou=people,o=fabrikam.com"
        dn = ManagementAgent.EscapeDNComponent(rdn).Concat(container)

        Dim oc As ValueCollection
        oc = Utils.ValueCollection("top")
        oc.Add("person")
        oc.Add("organizationalPerson")
        oc.Add("inetOrgPerson")

        Dim csentry As CSEntry
        csentry = ManagementAgent.Connectors.StartNewConnector("inetOrgPerson", oc)
        csentry.CommitNewConnector()
        SetIPlanetPW(csentry, mventry("employeeID").Value)
   End If
End Sub

Private Sub SetIPlanetPW(ByRef csentry As CSEntry, _
                        ByVal pw As String)
   Dim rawpw() As Byte
   rawpw = System.Text.UTF8Encoding().GetBytes(pw)
   csentry("userPassword").Values.Add(rawpw)
End Sub
void IMVSynchronization.Provision (MVEntry mventry)
{
    ConnectedMA ManagementAgent;
    int Connectors;
    ReferenceValue dn;
    string container;
    string rdn;

    ManagementAgent = mventry.ConnectedMAs["iPlanet MA"];
    Connectors = ManagementAgent.Connectors.Count;

    if(0 == Connectors)
    {
        rdn = "CN=" + mventry["cn"].Value;
        container = "ou=people,o=fabrikam.com";
        dn = ManagementAgent.EscapeDNComponent(rdn).Concat(container);
        ValueCollection oc;
        oc = Utils.ValueCollection("top");
        oc.Add("person");
        oc.Add("organizationalPerson");
        oc.Add("inetOrgPerson");

        CSEntry csentry;
        csentry = ManagementAgent.Connectors.StartNewConnector(
                                                "inetOrgPerson", oc);
        csentry.CommitNewConnector();
        SetIPlanetPW(csentry, mventry["employeeID"].Value);
    }
}

void SetIPlanetPW(CSEntry csentry, string pw) {
    byte[] rawpw = System.Text.UTF8Encoding.UTF8.GetBytes(pw)
    csentry["userPassword"].Values.Add(rawpw);
    return;
}

See Also

Reference

Provision

Concepts

Setting Initial Passwords