Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to change password and update database 1

Status
Not open for further replies.

ilpadrino

MIS
Feb 14, 2001
416
US
Does anyone have an idea of how to allow a user to change their password and at the same time update a field in a database (preferrably access)? I think this would have to be done with a script or maybe asp.

Thanks in advance.
 
You could do this with Vb i'm sure, i have a script that changes Active Directory passwords and one that puts logon info into an Access Db i'm sure they could be pulled together.
I'll post them when i get back to work.
 
The first script was written by Markdmac and will reset an Active Directory password.

Code:
'==========================================================================
'
' COMMENT: Script for changing Active Directory user passwords
'
'==========================================================================
Dim objuser, newpass, UserLDAP, lngFlag
Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000

Set objuser = GetObject(GetandBind)

newpass = InputBox("enter the new password")
changenextlogin = InputBox("Require User to change password at next logon?" & _
                            vbCrLf & "Y or N" & vbCrLf & _ 
                            "Default is Yes")



objUser.SetPassword newpass

If Ucase(left(changenextlogin,1)) <> "N" Then
    objUser.Put "PwdLastSet", 0
End If

objUser.SetInfo

lngFlag = objUser.Get("userAccountControl")
If (lngFlag And ADS_UF_DONT_EXPIRE_PASSWD) <> 0 Then
lngFlag = lngFlag Xor ADS_UF_DONT_EXPIRE_PASSWD
objUser.Put "userAccountControl", lngFlag
objUser.SetInfo
End If


Public Function GetandBind

Dim strname, UserLDAP, UserLDAPString

strname = InputBox("enter the username")

If strname ="" Then 
        WScript.Quit
    End If


    UserLDAP = "LDAP://" & SearchDistinguishedName(strname)

    On Error Resume Next   
    Set objUser = GetObject(UserLDAP)
    If Err <> 0 Then
        MsgBox "Invalid user ID. User not Found."
        GetandBind
    End If
    On Error GoTo 0
    MsgBox userLDAP

    GetandBind = UserLDAP

End Function



Public Function SearchDistinguishedName(ByVal vSAN)
    ' Function:     SearchDistinguishedName
    ' Description:  Searches the DistinguishedName for a given SamAccountName
    ' Parameters:   ByVal vSAN - The SamAccountName to search
    ' Returns:      The DistinguishedName Name
    Dim oRootDSE, oConnection, oCommand, oRecordSet

    Set oRootDSE = GetObject("LDAP://rootDSE")
    Set oConnection = CreateObject("ADODB.Connection")
    oConnection.Open "Provider=ADsDSOObject;"
    Set oCommand = CreateObject("ADODB.Command")
    oCommand.ActiveConnection = oConnection
    oCommand.CommandText = "<LDAP://" & oRootDSE.get("defaultNamingContext") & _
        ">;(&(objectCategory=User)(samAccountName=" & vSAN & "));distinguishedName;subtree"
    Set oRecordSet = oCommand.Execute

    On Error Resume Next
    SearchDistinguishedName = oRecordSet.Fields("DistinguishedName")
    On Error GoTo 0
    oConnection.Close
    Set oRecordSet = Nothing
    Set oCommand = Nothing
    Set oConnection = Nothing
    Set oRootDSE = Nothing
End Function


This second script enters data into an access file, i'm pretty sure someone in the VB forum will be able to help you merge the two. This script does use MS JET so the stations would require that installed (it's installed by access usually).


Code:
'This script records logon information for users with admin rights and records it to a
'database located on a hidden network share on the web server.


On Error Resume Next

Dim adoCn
Dim adoRs
Dim network
Dim user
Dim compname
Dim strSQLInsert


Set network = CreateObject("Wscript.Network")
user = network.username
compname = network.computername

Set adoCn = CreateObject("ADODB.Connection")

adoCn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
           "Data Source=\\server\logs$\log.mdb" 'CHANGE THIS BIT

'Check the connection opened ok           
If Err.Number <> 0 Then           
	Call ErrHandler
End If


strSQLInsert = "INSERT INTO [Log On] ([date], [time], [user], compname) " & _  
	"VALUES ('" & Date & "', '" & Time & "', '" & user & "', '" & compname & "')"

adoCn.Execute strSQLInsert, , 8

'Check the data was inserted OK
If Err.Number <> 0 Then           
	Call ErrHandler
End If

adoCn.Close

Set adoCn = Nothing
Set network = Nothing





Sub ErrHandler()
Dim fso, f

Const ForReading = 1, ForWriting = 2, ForAppending = 8

Set fso = CreateObject("Scripting.FileSystemObject")

Set f = fso.OpenTextFile("\\server\logs$\" & LogError & ".txt" , ForAppending, True)

f.WriteLine Date & ", " & Time & ", " & user & ", " & compname & ", " & Chr(34) & Err.Description & Chr(34)
f.Close

Set fso = nothing

Err.Clear

End Sub
 
thanks, the script runs, but doesn't actually change the password. so i'm looking into that.
 
If the user you are running as isn't an admin then you will need to delagate control of the OU to the appropriate users.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top