Created
June 21, 2018 08:54
-
-
Save ckruse/3a658d0270b01b89288d731ca9a6f3c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
import random | |
class FilterModule(object): | |
def salt(self): | |
ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
chars=[] | |
for i in range(16): | |
chars.append(random.choice(ALPHABET)) | |
return "".join(chars) | |
def setup_password(self, password): | |
md5 = hashlib.md5() | |
sha1 = hashlib.sha1() | |
md5.update(self.salt()) | |
salt = md5.hexdigest() | |
sha1.update(salt + ":" + password) | |
return salt + ":" + sha1.hexdigest() | |
def filters(self): | |
return { | |
'setup_password': self.setup_password | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment