pwauth.py
Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 
00003 """
00004 usage: %(progname)s [args]
00005 """
00006 
00007 
00008 import os, sys, string, time, getopt
00009 from pyclearsilver.log import *
00010 
00011 import random
00012 #import fcrypt as crypt
00013 import crypt
00014 
00015 def cryptPassword(password):
00016   # genereate new password hash
00017   salt = chr(random.randint(65,122)) + chr(random.randint(65,122))
00018   pwhash = crypt.crypt(password,salt)
00019   return pwhash
00020 
00021 def checkPassword(password, pw_hash):
00022   new_pw_hash = crypt.crypt(password,pw_hash[:2])
00023   if new_pw_hash != pw_hash: 
00024     warn("new_pw_hash", repr(new_pw_hash), repr(pw_hash))
00025     return 0
00026   return 1
00027 
00028 
00029 def encode_digest(digest):
00030     hexrep = []
00031     for c in digest:
00032         n = (ord(c) >> 4) & 0xf
00033         hexrep.append(hex(n)[-1])
00034         n = ord(c) & 0xf
00035         hexrep.append(hex(n)[-1])
00036     return ''.join(hexrep)
00037 
00038 def decode_digest(digest):
00039   code = []
00040   for n in range(0, len(digest), 2):
00041     a = chr(string.atoi(digest[n:n+2], 16))
00042     code.append(a)
00043   return string.join(code, '')
00044     
00045   
00046     
00047 
00048 def mungePassword(password):
00049   import zlib
00050   mpw = zlib.compress(password)
00051 
00052   mpw = encode_digest(mpw)
00053 
00054   mpw = list(mpw)
00055   mpw.reverse()
00056   mpw = string.join(mpw, '')
00057   return mpw
00058 
00059 def unmungePassword(mpassword):
00060   import zlib
00061 
00062   mpassword = list(mpassword)
00063   mpassword.reverse()
00064   mpassword = string.join(mpassword, '')
00065 
00066   mpassword = decode_digest(mpassword)
00067 
00068   password = zlib.decompress(mpassword)
00069   return password
00070   
00071   
00072 def test():
00073   pass
00074 
00075 def usage(progname):
00076   print __doc__ % vars()
00077 
00078 def main(argv, stdout, environ):
00079   progname = argv[0]
00080   optlist, args = getopt.getopt(argv[1:], "", ["help", "test", "debug"])
00081 
00082   testflag = 0
00083   if len(args) == 0:
00084     usage(progname)
00085     return
00086   for (field, val) in optlist:
00087     if field == "--help":
00088       usage(progname)
00089       return
00090     elif field == "--debug":
00091       debugfull()
00092     elif field == "--test":
00093       testflag = 1
00094 
00095   if testflag:
00096     test()
00097     return
00098 
00099 
00100 if __name__ == "__main__":
00101   main(sys.argv, sys.stdout, os.environ)


webui
Author(s): Scott Hassan/hassan@willowgarage.com
autogenerated on Wed Apr 23 2014 10:36:00