Asp中隨機(jī)產(chǎn)生用戶密碼的代碼
更新時(shí)間:2007年04月08日 00:00:00 作者:
隨機(jī)產(chǎn)生用戶密碼(good),說明:通過隨機(jī)產(chǎn)生密碼,然后將密碼EMail給注冊(cè)用戶,你可以確認(rèn)用戶的EMail填寫是否正確。
說明:通過隨機(jī)產(chǎn)生密碼,然后將密碼EMail給注冊(cè)用戶,你可以確認(rèn)用戶的EMail填寫是否正確。自動(dòng)產(chǎn)生的密碼往往安全性更高,同時(shí),你可以過濾那些無效的用戶。
把下面的代碼保存為random.asp文件:
<%
Sub StrRandomize(strSeed)
Dim i, nSeed
nSeed = CLng(0)
For i = 1 To Len(strSeed)
nSeed = nSeed Xor ((256 * ((i - 1) Mod 4) * AscB(Mid(strSeed, i, 1))))
Next
Randomize nSeed
End Sub
Function GeneratePassword(nLength)
Dim i, bMadeConsonant, c, nRnd
Const strDoubleConsonants = "bdfglmnpst"
Const strConsonants = "bcdfghklmnpqrstv"
Const strVocal = "aeiou"
GeneratePassword = ""
bMadeConsonant = False
For i = 0 To nLength
nRnd = Rnd
If GeneratePassword <> "" AND (bMadeConsonant <> True) AND (nRnd < 0.15) Then
c = Mid(strDoubleConsonants, Int(Len(strDoubleConsonants) * Rnd + 1), 1)
c = c & c
i = i + 1
bMadeConsonant = True
Else
If (bMadeConsonant <> True) And (nRnd < 0.95) Then
c = Mid(strConsonants, Int(Len(strConsonants) * Rnd + 1), 1)
bMadeConsonant = True
Else
c = Mid(strVocal,Int(Len(strVocal) * Rnd + 1), 1)
bMadeConsonant = False
End If
End If
GeneratePassword = GeneratePassword & c
Next
If Len(GeneratePassword) > nLength Then
GeneratePassword = Left(GeneratePassword, nLength)
End If
End Function
%>
然后在你的目標(biāo)程序中這樣調(diào)用上面的代碼,就可以實(shí)現(xiàn)密碼的自動(dòng)生成:(僅僅是一個(gè)例子,你可以把他們粘貼到一個(gè)Test.asp的文件中,然后運(yùn)行Test.asp)
<!--include file="random.asp" -->
<%
'產(chǎn)生一個(gè)六位的密碼
StrRandomize CStr(Now) & CStr(Rnd)
response.write GeneratePassword(6)
%>
<br><br>
<%
'產(chǎn)生一個(gè)8位的密碼
StrRandomize CStr(Now) & CStr(Rnd)
response.write GeneratePassword(8)
%>
<br><br>
<%
'產(chǎn)生一個(gè)10位的密碼
StrRandomize CStr(Now) & CStr(Rnd)
response.write GeneratePassword(10)
%>
<br><br>
<%
'產(chǎn)生1000個(gè)密碼
dim t, t2
for t = 1 to 500
For t2 = 1 to 661
StrRandomize CStr(Now) & CStr(Rnd)
next
StrRandomize CStr(Now) & CStr(Rnd)
response.write GeneratePassword(6)
response.write "<br>"
next
%>
說明:通過隨機(jī)產(chǎn)生密碼,然后將密碼EMail給注冊(cè)用戶,你可以確認(rèn)用戶的EMail填寫是否正確。自動(dòng)產(chǎn)生的密碼往往安全性更高,同時(shí),你可以過濾那些無效的用戶。
把下面的代碼保存為random.asp文件:
復(fù)制代碼 代碼如下:
<%
Sub StrRandomize(strSeed)
Dim i, nSeed
nSeed = CLng(0)
For i = 1 To Len(strSeed)
nSeed = nSeed Xor ((256 * ((i - 1) Mod 4) * AscB(Mid(strSeed, i, 1))))
Next
Randomize nSeed
End Sub
Function GeneratePassword(nLength)
Dim i, bMadeConsonant, c, nRnd
Const strDoubleConsonants = "bdfglmnpst"
Const strConsonants = "bcdfghklmnpqrstv"
Const strVocal = "aeiou"
GeneratePassword = ""
bMadeConsonant = False
For i = 0 To nLength
nRnd = Rnd
If GeneratePassword <> "" AND (bMadeConsonant <> True) AND (nRnd < 0.15) Then
c = Mid(strDoubleConsonants, Int(Len(strDoubleConsonants) * Rnd + 1), 1)
c = c & c
i = i + 1
bMadeConsonant = True
Else
If (bMadeConsonant <> True) And (nRnd < 0.95) Then
c = Mid(strConsonants, Int(Len(strConsonants) * Rnd + 1), 1)
bMadeConsonant = True
Else
c = Mid(strVocal,Int(Len(strVocal) * Rnd + 1), 1)
bMadeConsonant = False
End If
End If
GeneratePassword = GeneratePassword & c
Next
If Len(GeneratePassword) > nLength Then
GeneratePassword = Left(GeneratePassword, nLength)
End If
End Function
%>
復(fù)制代碼 代碼如下:
<!--include file="random.asp" -->
<%
'產(chǎn)生一個(gè)六位的密碼
StrRandomize CStr(Now) & CStr(Rnd)
response.write GeneratePassword(6)
%>
<br><br>
<%
'產(chǎn)生一個(gè)8位的密碼
StrRandomize CStr(Now) & CStr(Rnd)
response.write GeneratePassword(8)
%>
<br><br>
<%
'產(chǎn)生一個(gè)10位的密碼
StrRandomize CStr(Now) & CStr(Rnd)
response.write GeneratePassword(10)
%>
<br><br>
<%
'產(chǎn)生1000個(gè)密碼
dim t, t2
for t = 1 to 500
For t2 = 1 to 661
StrRandomize CStr(Now) & CStr(Rnd)
next
StrRandomize CStr(Now) & CStr(Rnd)
response.write GeneratePassword(6)
response.write "<br>"
next
%>
相關(guān)文章
asp中用數(shù)據(jù)庫生成不重復(fù)的流水號(hào)
asp中用數(shù)據(jù)庫生成不重復(fù)的流水號(hào)的實(shí)現(xiàn)代碼,需要的朋友可以參考下實(shí)現(xiàn)原理其它程序一樣。2006-09-09
ASP 獲取文件擴(kuò)展名函數(shù)getFileExt()
利用了asp的instrrev獲取最后.的位置,然后進(jìn)行截取,大家可以自己測試,其實(shí)編程過程也是大量的測試,慢慢就會(huì)發(fā)現(xiàn)更多的好東西。2009-08-08
asp實(shí)現(xiàn)讀取數(shù)據(jù)庫輸出json代碼
這篇文章主要介紹了asp實(shí)現(xiàn)讀取數(shù)據(jù)庫輸出json代碼的方法的相關(guān)資料,需要的朋友可以參考下2015-03-03
asp實(shí)現(xiàn)過濾關(guān)鍵字的函數(shù)
asp實(shí)現(xiàn)過濾關(guān)鍵字的函數(shù)...2007-08-08
ASP中用select case代替其他語言中的switch case, default用case else
這篇文章主要介紹了ASP中用select case代替其他語言中的switch case, default用case else ,需要的朋友可以參考下2015-11-11

