升级MD5.ASP,打造完全动态不重复的安全加密代码

10/16/2004来源:ASP技巧人气:21966

做一个完全动态的密码,让相同的密码生成不同的结果
密码aaa经过第一次运算后结果为:
jlce1d65ec3b91556234879c9db8f6da1123
第二次:
hjmnbe0d01cc1fbd3e18ae7431fa52fb3ce4
第三次:
grttb05901915e121d83ebefad7e809ef1b0
... ...
当然,亦可还原比较
以下我根据动网md5函数修改后的代码,
'=======================================
'Word 要加密的字符串
'返回加密后的 word
'例:response.write Md6("aaa")
'www.knowsky.com
'=======================================

Function Md6(Word)
Dim Random, RandomNum, reRandom, reWord
Randomize
Do While Len(Random) < 4
RandomNum = Chr(25 * rnd + 97 )
Random = Random & RandomNum
Loop                                                              
reRandom = Md5(Random)                         
reWord = Md5(Word)                                
Md6 = LCase(Random & Md5(reRandom + reWord))
End Function

'=======================================
'Wrod 需要验证的字符串,OldWord 加密后的原字符串
'返回比较后的结果,如果相等返回True,反之False
'例:pwd=“aaa“
'        old_pwd=“grttb05901915e121d83ebefad7e809ef1b0“
'        if Md6Back(pwd,old_pwd)=TRUE then
'        ... ...
'=======================================

Function Md6Back(Word, OldWord)
Dim Random, RandomNum, reRandom, reWord
Random = Mid(OldWord, 1, 4)                        
reRandom = Md5(Random)                          
reWord = Md5(Word)                    
If OldWord = Random & Md5(reRandom + reWord) Then
      Md6Back = True
  Else
      Md6Back = False
End If
End Function