ASP生成隨機密碼

2021-09-30 02:40:33 字數 2030 閱讀 9592

asp生成隨機密碼的兩個函式:

函式一<%

function makepassword(byval maxlen)

dim strnewpass

dim whatsnext, upper, lower, intcounter

randomize

for intcounter = 1 to maxlen

whatsnext = int((1 - 0 + 1) * rnd + 0)

if whatsnext = 0 then

'character

upper = 90

lower = 65

else

upper = 57

lower = 48

end if

strnewpass = strnewpass & chr(int((upper - lower + 1) * rnd + lower))

next

makepassword = strnewpass

end function

%>

makepassword(str) 'str 密碼的位數

函式二<% function gen_key(digits)

dim char_array(35)

char_array(0) = "0"

char_array(1) = "1"

char_array(2) = "2"

char_array(3) = "3"

char_array(4) = "4"

char_array(5) = "5"

char_array(6) = "6"

char_array(7) = "7"

char_array(8) = "8"

char_array(9) = "9"

char_array(10) = "a"

char_array(11) = "b"

char_array(12) = "c"

char_array(13) = "d"

char_array(14) = "e"

char_array(15) = "f"

char_array(16) = "g"

char_array(17) = "h"

char_array(18) = "i"

char_array(19) = "j"

char_array(20) = "k"

char_array(21) = "l"

char_array(22) = "m"

char_array(23) = "n"

char_array(24) = "o"

char_array(25) = "p"

char_array(26) = "q"

char_array(27) = "r"

char_array(28) = "s"

char_array(29) = "t"

char_array(30) = "u"

char_array(31) = "v"

char_array(32) = "w"

char_array(33) = "x"

char_array(34) = "y"

char_array(35) = "z"

randomize

do while len(output) < digits

num = char_array(int(35 * rnd + 0))

output = output + num

loop

gen_key = output

end function

%>

gen_key(str) 'str為密碼位數

這個函式還可以擴充套件。。如果你還要加上「大小寫敏感區分大小寫」特性的話,修改陣列大小為char_array(50),然後在後面列出所有可能的小寫字元。例如:

char_array(36) = "a"

char_array(37) = "b"

...............類推

生成隨機密碼

編寫乙個函式,用於生成隨機密碼,入參為隨機密碼的長度,出參為生成的隨機密碼,要求生成的隨機密碼必須同時包含大寫字母小寫字母數字。生成隨機碼,引數為隨機碼長度,同時包含大小寫字母和數字 public string getrandomnum int length listlist new arrayli...

php生成隨機密碼

隨機密碼生成 post number 0 數字 0 不啟用 1 啟用 post lowercase 0 小寫字母 post uppercase 0 大寫字母 post punctuation 1 特殊符號 post repeat 0 字元 1重複 0不重複 post length 31 密碼長度 p...

PowerShell生成隨機密碼

需求是這樣的,給員工重置密碼,密碼要是隨機的,但是0和o i和i這些不要,防止誤殺。我用的方法是這樣的,這是c 中web的乙個方法,很給力。assembly add type assemblyname system.web global passwordrandom system.web.secur...