初學|對象|加密|解決|問題 我的密碼的加密方法:
首先寫一個加密函數encrypt(str):
<%
function encrypt(str)
Dim i,c,length,texts,seed
length = len(str)
texts = ""
for i = 1 to length
c = mid(str,i,length)
seed=Asc(c)
if seed >ASC("hh") then //
seed=seed-15 //防止溢出問題
end if //
seed=i+length+seed
texts = texts & chr(seed)
next
texts = texts & mid(str,length,length)
encrypt =texts
end function
%>
上面用的vbscript函數:
len(str) 返回字串中的字元數目
Asc() 返回每一個字串首字母的 ANSI 字元代碼
Chr() 函數返回與指定的字元代碼相對應的字元
mid(str,i,length)返回字串str中從第i個字元開始的length個字元
另外再輸入密碼那個環節,用js控制只能輸入
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789
並限制數落密碼長度,12應該可以了吧
實現函數
function CharsInBag (s, bag)
{
var i;
for (i = 0; i < s.length; i++)
{
var c = s.charAt(i); //提取字串中的字元
if (bag.indexOf(c) == -1) return false;
}
return true;
}
寫資料的時候前面:
password =encrypt(request("password"))
password =replace(password,"'","''") 防止可怕的'
效果
密碼: 1111
加密後密碼: 789:;1
密碼: 00zzzzzzzz
加密後密碼: ;<xyz{|}~z
就這麼簡單^^
演算法可以根據自己喜好自己改