mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Added a saltHash function.
This commit is contained in:
parent
80deb23897
commit
b63f2170e8
11
src/utils.py
11
src/utils.py
@ -39,6 +39,8 @@ import fix
|
||||
|
||||
import os
|
||||
import re
|
||||
import md5
|
||||
import sha
|
||||
import string
|
||||
import sgmllib
|
||||
import textwrap
|
||||
@ -403,6 +405,15 @@ def flatten(seq, strings=False):
|
||||
except TypeError:
|
||||
yield elt
|
||||
|
||||
def saltHash(password, salt=None, hash='sha'):
|
||||
if salt is None:
|
||||
salt = mktemp()[:8]
|
||||
if hash == 'md5':
|
||||
hasher = md5.md5
|
||||
elif hash == 'sha':
|
||||
hasher = sha.sha
|
||||
return salt + hasher(salt + password).hexdigest()
|
||||
|
||||
class IterableMap(object):
|
||||
"""Define .iteritems() in a class and subclass this to get the other iters.
|
||||
"""
|
||||
|
@ -275,6 +275,10 @@ class UtilsTest(unittest.TestCase):
|
||||
self.failUnless(len(f('x'*35, 30)) <= 30)
|
||||
self.failUnless(f(' '.join(['xxxx']*10), 30)[:-3].endswith('xxxx'))
|
||||
|
||||
def testSaltHash(self):
|
||||
s = utils.saltHash('jemfinch')
|
||||
self.assertEqual(utils.saltHash('jemfinch', salt=s[:8]), s)
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user