答复: 一种简单的给MD5加盐算法
原文 http://www.iteye.com/topic/1127277
python实现
python实现
#!/usr/bin/env python #coding:utf-8 import random import hashlib DIGEST_LEN = 16 def generate(password): salt = '%0*d%0*d' % (8, random.randint(0, 99999999), 8, random.randint(0, 99999999)) password = hashlib.md5(str(password)+salt).hexdigest() cs = [] # size 48 for i in range(DIGEST_LEN): cs.append(password[i*2]) cs.append(salt[i]) cs.append(password[i*2+1]) return "".join(cs) def verify(password, md5): salt = [] md5_password = [] for i in range(DIGEST_LEN): salt.append(md5[i * 3 + 1]) md5_password.append(md5[i * 3]) md5_password.append(md5[i * 3 + 2]) return hashlib.md5(str(password) + "".join(salt)).hexdigest() == "".join(md5_password) if __name__ == '__main__': password = generate("123456") print verify("123456", password) # print "True"(文:程序员之家)
转载注明地址:http://www.verydemo.com
相关推荐
莫明天涯 2020-09-03
JF0 2020-06-14
rainchxy 2020-06-07
Ghero 2020-05-25
baike 2020-04-26
路漫 2020-04-11
seekerhit 2020-02-15
蜗牛慢爬的李成广 2020-02-15
lixiaotao 2020-01-03
wuxiaosi0 2020-01-03
蜗牛慢爬的李成广 2019-12-22
路漫 2019-12-22
baike 2019-12-12
luohui 2019-12-07
风吹夏天 2019-10-20
SongLynn 2019-09-05
ustbfym 2014-11-21
ZhuZhuWonder 2014-11-25
极乐净土 2011-12-16