PDA

View Full Version : Can SOMEONE Help? This one is driving me crazy


dvlnblk
06-26-2003, 03:44 PM
Okay, here is the deal. I am making an asp page that will look through an access database and give each user a random password. Then send out a CDONTS email. I know how to do the CDONTS but I cannot get the random password to work right. I have the password generator but when I loop through the recordset it changes all of the records to the same random password.


Here is the code I have thus far:

<%
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
%>

Can anyone help me with this one, I have spent the whole day trying to figure it out. Thanks, DVL

aghill
06-26-2003, 03:53 PM
Right after I made the post.. I realized that your problem was something else... so I deleted it.

dvlnblk
06-26-2003, 03:57 PM
Does that mean you have no idea of how I can fix it? LOL DVL

aghill
06-26-2003, 03:59 PM
Sorry, no ideas here. :confused:

jsawkang
06-27-2003, 01:15 AM
Hi...

If all the password in the record changed to the new generated password, that mean there is something wrong ur SQL query.

ur code:
"UPDATE users SET pass = (' " & strTemp & "')"
query above will set pass in all the record =" & strTemp & "

so u need to specify a specific record to UPDATE.
example: the unique field is userid.
so u have to get that unique id first.
for me, i usually use "Select MAX(userid) as maxid from users"

"UPDATE users SET pass ='" & strTemp & "' WHERE userid=" &rs("maxid")& ""

try it out. maybe can solved ur problem

dvlnblk
06-27-2003, 01:43 AM
But if I do this then I will only change the highest (ie., Max) id. I want to generate a code that will assign every record a different random password. How can I do that? By the way, thanks for the help. DVL

dvlnblk
06-27-2003, 01:46 AM
Wait, I have an idea. What if I set a variable like add to = 0. Then I change the password on the Min(id) + add to a random number. Then I set add = add + 1. And then loop until EOF. Would that work? If so, in God's name do I do it? LOL...DVL

jsawkang
06-27-2003, 02:17 AM
erm..

i think u can select all the record i table users, then loop through it and at the same time update the record.

like
SQL="Select * from users"
set rs=cn.execute(SQL)
while not rs.eof
*generate ur random password.

sSQL="UPDATE users SET pass ='" & strTemp & "' WHERE userid=" &rs("usersid")& ""
set rec=cn.execute(sSQL)

rs.movenext
wend

dvlnblk
06-27-2003, 02:34 AM
I don't understand this code:

sSQL="UPDATE users SET pass ='" & strTemp & "' WHERE userid=" &rs("usersid")& ""

can you break it down for me...epecially &rs("usersid")& "" part

DVL

jsawkang
06-27-2003, 03:01 AM
rs("usersid") also same as rs.field("usersid")


why it's that way? becoz rs("usersid") is from another query. so evertime it loop through next record, rs("usersid") will changed. so u can set different pass to each record.

do u undestand? in my previous posting? got two SQL query rite?
the first query loop through the record 1 by 1. the second query in the looping (while not rs.eof) update the pass.