473,574 Members | 3,135 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inserting Random Passwords into Database

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 (in**@carl-mercier.com)</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(myLeng th)
'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) + 48))
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='insertP asswordsADMIN.a sp'>" & vbCrLf
For X = 0 To 326
'Response.Write RandomPW(5) & "<br>" & vbCrLf
Response.Write "<input type='text' name='GenPassWo rd'
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 'insertPassword sADMIN.asp':
=============== =============== =============== ==

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

<%
var conn;
var rs;
var sSQL;

rs=Server.Creat eObject("ADODB. Recordset");
conn = Server.CreateOb ject("ADODB.con nection");
conn.Open("myda ta");

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

rs.Open(sSQL,co nn);
//Response.write( sSQL);
if (!rs.eof) {
while (!rs.eof){

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

//expecting values

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

rs = conn.Execute(sS QL);
rs.MoveNext();
}
}

%>
=============== =============== =============== ==
....This line 'rs = conn.Execute(sS QL);' 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
Jul 19 '05 #1
14 4053
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("A DODB.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/
Jul 19 '05 #2
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!
Jul 19 '05 #3
> 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
Jul 19 '05 #4

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!
Jul 19 '05 #5
Okay, so you would do this:

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

set conn = CreateObject("A DODB.connection ")
conn.open "mydata"

set rs = conn.execute("S ELECT 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" <in**@mirandajo hnsen.com> wrote in message
news:uS******** ******@TK2MSFTN GP11.phx.gbl...

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!

Jul 19 '05 #6
> 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/
Jul 19 '05 #7
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!
Jul 19 '05 #8
> 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 certificateNumb er 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!
Jul 19 '05 #9
> 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/
Jul 19 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1488
by: Joe | last post by:
Hi, I am building web in ASP.NET using VB.NET to code the pages. I want to generate random passwords for users. I know that password hashing is built right into the .NET Framework. I was wondering if there is any built-in support for generating random passwords in .Net. If the support is built-in, can you show me how to do it. Thanks, ...
2
1575
by: Joe | last post by:
Hi, I want to generate a random password every time a new user account is created. I want to include small and capital letters and 0 to 9 digits. Can someone give me some idea as how should I do it? I am a beginner in ASP.NET and using VB.net to code the pages so please do not give me any clues in C# because I don’t know that language. ...
5
3924
by: k.i.n.g. | last post by:
Hi, I have a csv file which in taken as the input file for adding users in my linux mail server with the format userid,fullname,passwword,dateofbith Now I have to write a script to generate random password in the password field for each user. A simple algorithm is sufficient for passwords
24
2713
by: NoName | last post by:
Perl: @char=("A".."Z","a".."z",0..9); do{print join("",@char)}while(<>); !!generate passwords untill U press ctrl-z Python (from CookBook):
1
1793
by: ram achar | last post by:
please send me C# code for inserting values into database sql server2005 *** Sent via Developersdex http://www.developersdex.com ***
0
7841
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8101
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8271
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7858
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8137
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5335
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3774
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3793
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1369
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.