import hashlib import redis import string import random host= 'saltstack-23' #unix_time = 1459967387 user = 'douyuops' redis_ip = '192.168.1.82' redis_port = 6379 def decodepw(token,rd): spec_case = [x for x in '~!@#$%^&*()_+{}<>-='] + [x for x in string.lowercase] rd_list = [int(x) for x in rd.split('&')] reset_token = '' for x in range(len(token)): if x in rd_list: w = spec_case[x] else: w = token[x] reset_token += w return reset_token def getpw(): r = redis.StrictRedis(host=redis_ip, port=redis_port, db=0) unix_time = r.get(host) token_rd = r.get(host + 'rd') token_hostname = hashlib.md5(host).hexdigest()[10:] token_loginuser = hashlib.md5(user).hexdigest()[10:] token_unix_time = hashlib.md5(str(int(unix_time) / 300)).hexdigest()[10:] token = hashlib.md5(token_hostname + token_loginuser + token_unix_time).hexdigest()[10:].upper() return decodepw(token, token_rd) print getpw()