将随机密码插入数据库 [英] Inserting Random Passwords into Database

查看:52
本文介绍了将随机密码插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生成随机密码的ASP / vbscript程序。

问题是我需要将这些密码插入到

327客户端的Access数据库中。


我有随机密码程序生成327密码,但

没有运气插入它们。

==================== ===========================

以下是生成密码的代码:

===============================================

<%Option明确%>

<%

Dim X

Response.Write"< ; HTML>" &安培; vbCrLf

Response.Write"< HEAD>" &安培; vbCrLf

Response.Write"< TITLE> ASP随机密码生成器v1.1 - 由Carl

Mercier(在** @ carl-mercier.com)< / TITLE>" &安培; vbCrLf

Response.Write"< / HEAD>" &安培; vbCrLf

Response.Write"< BODY>" &安培; vbCrLf

Response.Write"< FONT FACE = COURIER>" &安培; vbCrLf


Response.Write"< B>固定长度(5个字符)密码< / B>< BR>" &

vbCrLf


对于X = 0到326

''Response.Write RandomPW(5)& "<峰; br>" &安培; vbCrLf

下一页


Response.Write"< / FONT>" &安培; vbCrLf

Response.Write"< / BODY>" &安培; vbCrLf

Response.Write"< / HTML>" &安培; vbCrLf


函数RandomPW(myLength)

''这些常量是随机

''长度密码的最小和最大长度。根据您的需要调整这些值。

Const minLength = 5

Const maxLength = 5

Dim X,Y,strPW


如果myLength = 0那么

随机化

myLength = Int((maxLength * Rnd)+ minLength)

结束如果

X = 1到myLength

''随机化这个角色的类型

Y = Int((3 * Rnd)+ 1)''(1)数字,(2)大写,(3)小写


选择案例Y

案例1

''数字字符

随机化

strPW = strPW& CHR(Int((9 * Rnd)+ 48))

案例2

''大写字符

随机化

strPW = strPW& CHR(Int((25 * Rnd)+ 65))

案例3

''小写字符

随机化

strPW = strPW& CHR(国际((25 * Rnd)+ 97))


结束选择

下一页


RandomPW = strPW


结束功能


%>

============ ===================================

我试过了:

============================================== =

Response.Write"< B>固定长度(5个字符)密码< / B>< BR>" &

vbCrLf

Response.Write"< form method =''post''

action =''insertPasswordsADMIN.asp' >" &安培; vbCrLf

对于X = 0到326

''Response.Write RandomPW(5)& "<峰; br>" &安培; vbCrLf

Response.Write"< input type =''text''name =''GenPassWord''

value =''RandomPW(5)''> ;"&安培; vbCrLf


下一页

Response.Write"< input type =''submit''name =''update''value =''更新' '>"&

vbCrLf

Response.Write"< / form>" &安培; vbCrLf

========================================= ======

....没有运气。

==================== ===========================

=============== ================================

这是我的代码''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 + ="来自投资;


rs.Open(sSQL,conn);

//Response.write(sSQL);

if( !rs.eof){

while(!rs.eof){


sSQL + ="插入INTO invest" ;;

sSQL + =" (InvestPassword)" ;;


//期待值


sSQL + =" VALUES("

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


rs = conn.Execute(sSQL);

rs.MoveNext();

}

}

%>

================================== =============

....这一行''rs = conn.Execute(sSQL);''咳出一个错误?

============================================= ==

现在,我的一个问题是密码生成器是VBScript,

和我用JavaScript代码。虽然我已经理解了

VBscript不得不将其翻译成JavaScript - 我肯定是

不是专业人士。

我替代这就是手动将密码插入到数据库中,我真的不愿意这样做!


任何建议都将不胜感激!!

提前感谢任何想帮助我解决这个问题的人。


Miranda Johnsen

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(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) + 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=''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

推荐答案

为什么需要两个页面和一个表单来执行此操作?此外,即使您在JavaScript中编码

,因为您在VBScript中有一个方法(我认为这只是一个管理员,一个只需要的一次性页面)运行一次),为什么不能将整个页面整个页面放在VBScript中?在一次性页面中,为什么传递给randomPW函数的长度

必须是可变的?你为什么使用

DSN(见 http://www.aspfaq.com/2126)?最后,与我的有什么关系?前缀

到处都是...我应该期待在其他功能上找到前缀

和变量名,比如他,她,Bob'等等? br />

<%

函数randomPW(长度)

随机化

...

randomPW =无论

结束函数


set conn = CreateObject(" ADODB.connection")

conn.openmydata

for x = 0 to 326

sql =" INSERT invest(InvestPassword)" &安培; _

" VALUES(''"& randomPW(5)&"'')"

conn.execute sql ,, 129

next

conn.close:set conn = nothing

%>


就是这样。只需点击页面,喝杯咖啡,当你回来时,你就会在表中投入327个随机密码。注意:我没有

检查RandomPW功能是否可以优化,也没有做任何事情以防止多个密码相同。


-

Aaron Bertrand

SQL Server MVP
http://www.aspfaq.com/
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/


Aaron,

感谢您之前的回复。

只是为了让您知道myWhatevers已经在代码中了,当我得到它的时候(我没写过)。而且我只使用''myData''来作为一个

DSN的例子,这不是我真正的名字。我知道我应该使用

DSN-less连接,现在它可以正常工作......


我做了你推荐的并且它有效,但它没有将

密码插入正确的行。我已经在

这个表中有几个其他列有关于200多个客户的信息(一些客户有多个
多行,所以我想我应该测试一下clientID并且只有每个clientID插入一个密码值
。我已经在表格中添加了密码

colum,现在我需要将密码插入到客户的空白

记录中。

当我运行程序时发生的事情是,它在客户端之前插入了

300+密码,最终我有600多行,但仍然是

没有客户密码。我有意义吗?

你知道如何解决这个问题吗?


再次感谢,

Miranda



***通过开发人员指南 http:// www。 developersdex.com ***

不要只是参加USENET ......获得奖励!
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!


> ;我做了你推荐的并且它有效,但它没有将
> I did what you recomended and it worked, but it is not inserting the
密码插入到正确的行中。我已经在这个表中有几个其他列有关于200多个客户端的信息(一些客户端有多行,所以我想我应该测试clientID并且只插入
每个clientID一个密码值)。我已经在表格中添加了密码
colum,现在我需要将密码插入到客户的空白
记录中。
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.




然后你需要一个更新声明,而不是插入声明!


但是,在我告诉你如何继续之前,我需要知道你的是什么
主键是。


A



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


这篇关于将随机密码插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆