Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Inserting Random Passwords into Database

Reply
Thread Tools

Inserting Random Passwords into Database

 
 
Miranda
Guest
Posts: n/a
 
      12-04-2003
Hi, I have a ASP/vbscript program that generates random passwords. The
problem is I need to insert those passwords into an Access database of
327 clients.

I have the random password program generating the 327 passwords, but
have had no luck inserting them.
===============================================
Here is the code that generates the passwords:
===============================================
<% Option Explicit %>
<%
Dim X
Response.Write "<HTML>" & vbCrLf
Response.Write "<HEAD>" & vbCrLf
Response.Write "<TITLE> ASP Random Password Generator v1.1 - by Carl
Mercier ()</TITLE>" & vbCrLf
Response.Write "</HEAD>" & vbCrLf
Response.Write "<BODY>" & vbCrLf
Response.Write "<FONT FACE=COURIER>" & vbCrLf

Response.Write "<B>Fixed length (5 character) passwords</B><BR>" &
vbCrLf

For X = 0 To 326
'Response.Write RandomPW(5) & "<br>" & vbCrLf
Next

Response.Write "</FONT>" & vbCrLf
Response.Write "</BODY>" & vbCrLf
Response.Write "</HTML>" & vbCrLf



Function RandomPW(myLength)
'These constant are the minimum and maximum length for random
'length passwords. Adjust these values to your needs.
Const minLength = 5
Const maxLength = 5

Dim X, Y, strPW

If myLength = 0 Then
Randomize
myLength = Int((maxLength * Rnd) + minLength)
End If


For X = 1 To myLength
'Randomize the type of this character
Y = Int((3 * Rnd) + 1) '(1) Numeric, (2) Uppercase, (3) Lowercase

Select Case Y
Case 1
'Numeric character
Randomize
strPW = strPW & CHR(Int((9 * Rnd) + 4)
Case 2
'Uppercase character
Randomize
strPW = strPW & CHR(Int((25 * Rnd) + 65))
Case 3
'Lowercase character
Randomize
strPW = strPW & CHR(Int((25 * Rnd) + 97))

End Select
Next

RandomPW = strPW

End Function

%>
===============================================
I tried:
===============================================
Response.Write "<B>Fixed length (5 character) passwords</B><BR>" &
vbCrLf
Response.Write "<form method='post'
action='insertPasswordsADMIN.asp'>" & vbCrLf
For X = 0 To 326
'Response.Write RandomPW(5) & "<br>" & vbCrLf
Response.Write "<input type='text' name='GenPassWord'
value='RandomPW(5)'>"& vbCrLf

Next
Response.Write "<input type='submit' name='update' value='Update'>"&
vbCrLf
Response.Write "</form>" & vbCrLf
===============================================
....with no luck.
===============================================
===============================================
Here is my code for 'insertPasswordsADMIN.asp':
===============================================

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<!--#include file="../adojavas.inc"-->

<%
var conn;
var rs;
var sSQL;

rs=Server.CreateObject("ADODB.Recordset");
conn = Server.CreateObject("ADODB.connection");
conn.Open("mydata");

sSQL = "SELECT InvestPassword ";
sSQL += " FROM invest ; "

rs.Open(sSQL,conn);
//Response.write(sSQL);


if (!rs.eof) {
while (!rs.eof){

sSQL += " Insert INTO invest ";
sSQL += " (InvestPassword)";

//expecting values

sSQL += " VALUES ("
sSQL += " '" + Request.form("GenPassWord") + "');"

rs = conn.Execute(sSQL);
rs.MoveNext();
}
}

%>
===============================================
....This line 'rs = conn.Execute(sSQL);' is coughing up an error??
===============================================
Now, one of my problems is that the password generator is in VBScript,
and I code in JavaScript. Although I have some understanding of
VBscript from having to translate it into JavaScript - I am definately
not a pro.
My alternative to figuring this out is inserting the passwords into
the database manually, I'd REALLY rather not do that!

Any Suggestions would be greatly appreciated!!
Thank you in advance for anybody who would like to help me tackle this
problem!

Miranda Johnsen
 
Reply With Quote
 
 
 
 
Aaron Bertrand - MVP
Guest
Posts: n/a
 
      12-04-2003
Why do you need two pages and a form to do this? Also, even though you code
in JavaScript, since you have a method in VBScript (and I assume this is
just an admin, one-off page that only needs to be run once), why can't the
whole page be in VBScript? And in a one-off page, why does the length
passed into the randomPW function have to be variable? Why are you using a
DSN (see http://www.aspfaq.com/2126)? Finally, what's with the "my" prefix
all over the place... should I expect to find prefixes on other functions
and variable names, like his, her, Bob's, etc?

<%
function randomPW(length)
randomize
...
randomPW = whatever
end function

set conn = CreateObject("ADODB.connection")
conn.open "mydata"
for x = 0 to 326
sql = "INSERT invest (InvestPassword)" & _
" VALUES('" & randomPW(5) & "')"
conn.execute sql, , 129
next
conn.close: set conn = nothing
%>

That's it. Just hit the page, get a coffee, and when you come back, you
will have 327 randomized passwords in the table invest. Note: I did not
inspect the RandomPW function to see if it could be optimized, nor did I do
anything to prevent multiple passwords from being identical.

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


 
Reply With Quote
 
 
 
 
Miranda johnsen
Guest
Posts: n/a
 
      12-05-2003
Aaron,
Thank you for your previous response.
Just to let you know the myWhatevers were already in the code when I got
it (I did'nt write it). And I only used 'myData' for an example for a
DSN, that's not what I've really named it. I know I should be using
DSN-less connections, right now it works so...

I did what you recomended and it worked, but it is not inserting the
passwords into the right rows. I already have several other columns in
this table that have info regarding the 200+ clients (some clients have
more than one row, so I guess I should be testing for clientID and only
inserting one password value per clientID). I've added the password
colum to the table and now I need to insert the passwords into the empty
records for the clients.


What is happening when I run the program as it is, is that it insert the
300+ passwords before the clients and I end up with 600+ rows, but still
no passwords for the clients. Am I making sense?
Do you know how to fix this??

Thanks again,
Miranda




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Aaron Bertrand [MVP]
Guest
Posts: n/a
 
      12-05-2003
> I did what you recomended and it worked, but it is not inserting the
> passwords into the right rows. I already have several other columns in
> this table that have info regarding the 200+ clients (some clients have
> more than one row, so I guess I should be testing for clientID and only
> inserting one password value per clientID). I've added the password
> colum to the table and now I need to insert the passwords into the empty
> records for the clients.


Then you need an update statement, not an insert statement!

However, before I can tell you how to proceed, I need to know what your
primary key is.

A


 
Reply With Quote
 
Miranda johnsen
Guest
Posts: n/a
 
      12-05-2003

I was wondering about that :s
The table I'm working in is called Investors, there is no primary key in
there, but the InvestorId is the Key to Investors File.
-Miranda

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Aaron Bertrand [MVP]
Guest
Posts: n/a
 
      12-05-2003
Okay, so you would do this:

<%
function randomPW(length)
'... blah ...
end function

set conn = CreateObject("ADODB.connection")
conn.open "mydata"

set rs = conn.execute("SELECT InvestorID FROM Invest")
do while not rs.eof
' assuming InvestorID is an integer!
sql = "UPDATE invest SET password = " & _
"'" & randomPW(5) & "'" & _
" WHERE InvestorID = " & InvestorID
conn.execute sql, , 129
rs.movenext
loop

rs.close: set rs = nothing
conn.close: set conn = nothing
%>

This certainly isn't very efficient. I'm also curious what you're going to
do when another investor gets added to the table...

If you were using MSDE or another flavor of SQL Server, this would be far,
far easier.

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/




"Miranda johnsen" <> wrote in message
news:...
>
> I was wondering about that :s
> The table I'm working in is called Investors, there is no primary key in
> there, but the InvestorId is the Key to Investors File.
> -Miranda
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



 
Reply With Quote
 
Aaron Bertrand [MVP]
Guest
Posts: n/a
 
      12-05-2003
> there is no primary key in there,

Why not? How do you plan to ensure data integrity?

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


 
Reply With Quote
 
Miranda johnsen
Guest
Posts: n/a
 
      12-05-2003
The Access Database I am using from extracted tables from the main
company database. Because there are so many clients, he exported
pertinent tables into a seperate web database so when content on the
main database changes, like a new client is added and so forth, he will
not have to enter redundant information online, he just re-exports the
tables to the web database and re-uploads the database.
Probably not the best way to go about it, but it works.

I have a seperate access database for non-client related data for
content that is only online.

As for generating a password for a new client, I don't think (I hope) I
will have too much troubel writing a page for him to generate a password
for a new user online. I could have it so he selects the member to add a
password for and run the script to generate it and update that record.

Ironically, I've spent more time trying to figure out how to do this
automatically than if I had of just put the values in manually!

This is one of the last steps in my project and I'm almost at my
deadline so I really the advice/help you have given me.
I'll let you know how it goes!
Cheers,
Miranda

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Miranda johnsen
Guest
Posts: n/a
 
      12-05-2003
> there is no primary key in there,
>Why not? How do you plan to ensure data integrity?


hm, well I have a database with 6 tables.
3 of these tables contain a Primary Key.
TableA and TableB have certificateNumber as their PrimaryKey. They also
have InvestorID in them. The Table I need, the InvestorsTable,where I
inserted the Password column, and also has the InvestorID in it.

I don't believe this convoluted explaination is helping to answer your
question. I guess my answer is I don't know :s
I didn't realize my integrity was at risk!
-miranda

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Reply With Quote
 
Aaron Bertrand [MVP]
Guest
Posts: n/a
 
      12-05-2003
> I don't believe this convoluted explaination is helping to answer your
> question. I guess my answer is I don't know :s
> I didn't realize my integrity was at risk!


First I'll state the disclaimer that this does not apply to every last
situation in the world. I have some tables without primary keys, and I can
explain why if you'd like.

However.

A table is meant to represent a set of unique entities. A primary key
enforces the fact that, whatever makes those entities unique, cannot be
repeated (and will always *uniquely* define that entity, or in simpler
terms, row). If you don't have a primary key (or a unique constraint,
though I'm not sure those are supported in Access) then it's difficult to
prevent your data from becoming corrupt. Depending on the complexity of
your schema, this corruption (e.g. having two investorIDs in your investors
table, for example) could be anywhere from mildly annoying, to downright
disastrous.

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Database Database Database scott93727@gmail.com Computer Information 0 09-27-2012 02:43 AM
DataBase DataBase DataBase DataBase scott93727@gmail.com Computer Information 0 09-26-2012 09:40 AM
Math.random() and Math.round(Math.random()) and Math.floor(Math.random()*2) VK Javascript 15 05-02-2010 03:43 PM
random.random(), random not defined!? globalrev Python 4 04-20-2008 08:12 AM
Retrieve ID after inserting into Access database refer_to_website@nospam.com ASP .Net 0 10-28-2003 10:07 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57