欢迎光临
我们一直在努力

加密QueryString数据

建站超值云服务器,限时71元/月

problem with query string method

often time we use query string collection to retrieve an unique record from a table. notice the following

piece of code –

detail.asp?recordid=200

here we are passing a query string value called "recordid" using the url. we then use the query string

collection "recordid" to get the actual number –

<%

dim recordid

recordid = request.querystring("recordid")

%>

the problem with the above method is that we are exposing "recordid" to the public. hence making easy to

hackers to just change the recordid query string to retrieve other values of the table.

solution to the above problem

in order to solve the above problem, we will use two asp pages and the asp random number function to

scramble the passing query string value so that the real record number is not exposed to others.

on the first page we get a random number with the following code –

<%

randomize timer

randomizing the timer function

rndnum = abs(int((rnd() * 3001)))

to generate a prime based, non-negative random number..

rndnum = rndnum + 53

session("rndnum") = rndnum

we place the random number value in a session variable so that we can use it again in the next page %>

now that we have our random number we will scramble our query string with it! here is how –

<%

assuming you have a record set retrieved –

display_rs.movefirst

while not display_rs.eof

response.write "<a href=detail.asp?recordid="

response.write (display_rs("recordid")*rndnum)

notice we are multiplying the actual record number with the random number to scramble the query string

response.write display_rs("recordid") & "</a>"

display_rs.movenext

wend

%>

in the next page we will un-scramble the query string! here is how –

<%

dim recordid

recordid = request.querystring("recordid")/session("rndnum")

we are dividing the record id query string value with the same formula to un-scramble and pass the

actual record id to the sql statement

session.abandon

releasing session value for the next record

%>

thats it! using the above method you can scramble a query string as much as you like. for example

multiply the random number with a very complex formula to generate an even more difficult integer number.

the key point here is you divide the number with the same formula yielding to the original value. this

technique is not full proof but much more difficult to break in that passing a regular query string value.

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 加密QueryString数据
分享到: 更多 (0)