import hashlib algs = [None, 'sha1', 'sha256', 'sha512'] def hash(algo, passwd): if algo == None: # None return passwd if algo == 'sha1': # sha1 return sha1(passwd) if algo == 'sha256': # sha256 return sha256(passwd) if algo == 'sha512': # sha512 return sha512(passwd) return passwd def sha1(passwd): return hashlib.sha1(passwd).hexdigest() def sha256(passwd): return hashlib.sha256(passwd).hexdigest() def sha512(passwd): return hashlib.sha512(passwd).hexdigest()