[Checkins] SVN: grokproject/trunk/grokproject/utils.py Add function for SHA1 encoding strings.

Uli Fouquet uli at gnufix.de
Wed Feb 18 08:53:04 EST 2009


Log message for revision 96697:
  Add function for SHA1 encoding strings.

Changed:
  U   grokproject/trunk/grokproject/utils.py

-=-
Modified: grokproject/trunk/grokproject/utils.py
===================================================================
--- grokproject/trunk/grokproject/utils.py	2009-02-18 13:21:54 UTC (rev 96696)
+++ grokproject/trunk/grokproject/utils.py	2009-02-18 13:53:04 UTC (rev 96697)
@@ -1,9 +1,12 @@
+import codecs
 import os
 import sys
+import sha
 import shutil
 import tempfile
 import pkg_resources
 import logging
+from random import randint
 from paste.script.templates import var
 
 HOME = os.path.expanduser('~')
@@ -45,6 +48,15 @@
         config_file.write(contents)
         config_file.close()
 
+def get_sha1_encoded_string(passwd):
+    """Encode the given `string` using SHA1.
+    """
+    encoder = codecs.getencoder('utf-8')
+    salt = "%08x" % randint(0, 0xffffffff)
+    # This is apparently a wrong use of salt, but the old SHA1
+    # password manager of `zope.app.authentication` handles it this way.
+    result = salt + sha.new(encoder(passwd)[0]).hexdigest()
+    return result
 
 def get_boolean_value_for_option(vars, option):
     value = vars.get(option.name)



More information about the Checkins mailing list