PDA

View Full Version : Automatic Update


dvlnblk
06-26-2003, 06:22 PM
Hi all, I cannot for the life of me figure out how to do this so maybe one of you can help.

I have a simple access DB with 3 fields, email, pass and id. I need the code that will loop through all of the records and assign a random password.

Can anyone Please help? Thanks in advance, DVL

Bullschmidt
06-27-2003, 12:48 AM
How about creating an update query that puts in the following into the password field:

Rnd([MyPrimaryKeyField)

Of course the password will then be a boring number, but at least it will be random.

dvlnblk
06-27-2003, 01:48 AM
That sounds and I actually did that, use RND that is. But I need to loop through and give each record a random password. How can I do that? Here is the code I used but it changes every record to the last random genereated password.

<%
While ((Repeat1__numRows <> 0) AND (NOT RS1.EOF))
%>
<%
Dim fs, i, x
Dim strTemp
Set fs = CreateObject("Scripting.FileSystemObject")
For x = 1 to 1
'Get just the filename part of the temp name path
strTemp = fs.GetBaseName(fs.GetTempName)

'Hack off the 'rad'
strTemp = Right(strTemp, Len(strTemp) - 3)
Next%>

uname: <%=(RS1.Fields.Item("email").Value)%> - pass: <%=Response.Write(strTemp)%> <BR><%Set fs = Nothing %>
<% Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_hamid_STRING

MM_editCmd.CommandText = "UPDATE users SET pass = (' " & strTemp & "')"
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
%>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
RS1.MoveNext()
Wend
%>
</body>
</html>
<%
RS1.Close()
Set RS1 = Nothing
%>

webster252003
06-29-2003, 03:09 AM
Try this one problem I had with this code is that it kept changing.
Should work. Find me useful visit my website for more help.

<%
genPassword = ""
Randomize
For i = 1 to 15
intNum = Int(10 * Rnd + 48)
intUpper = Int(26 * Rnd + 65)
intLower = Int(26 * Rnd + 97)
intRand = Int(3 * Rnd + 1)
Select Case intRand
Case 1
strPartPass = Chr(intNum)
Case 2
strPartPass = Chr(intUpper)
Case 3
strPartPass = Chr(intLower)
End Select
genPassword = genPassword & strPartPass
Next
%>
....Other stuff here
<%
While ((Repeat1__numRows <> 0) AND (NOT RS1.EOF))
%>
<%
Dim fs, i, x
Dim strTemp
Set fs = CreateObject("Scripting.FileSystemObject")
For x = 1 to 1
'Get just the filename part of the temp name path
strTemp = fs.GetBaseName(fs.GetTempName)

'Hack off the 'rad'
strTemp = Right(strTemp, Len(strTemp) - 3)
Next%>

uname: <%=(RS1.Fields.Item("email").Value)%> - pass: <%=Response.Write(strTemp)%> <BR><%Set fs = Nothing %>
<% Set MM_editCmd = Server.CreateObject("ADODB.Command")
MM_editCmd.ActiveConnection = MM_hamid_STRING

MM_editCmd.CommandText = "UPDATE users SET pass = genPassword;"
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
%>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
RS1.MoveNext()
Wend
%>
</body>
</html>
<%
RS1.Close()
Set RS1 = Nothing
%>