pwauth.py
Go to the documentation of this file.
1 #! /usr/bin/env python
2 
3 """
4 usage: %(progname)s [args]
5 """
6 
7 
8 import os, sys, string, time, getopt
9 from pyclearsilver.log import *
10 
11 import random
12 #import fcrypt as crypt
13 import crypt
14 
15 def cryptPassword(password):
16  # genereate new password hash
17  salt = chr(random.randint(65,122)) + chr(random.randint(65,122))
18  pwhash = crypt.crypt(password,salt)
19  return pwhash
20 
21 def checkPassword(password, pw_hash):
22  new_pw_hash = crypt.crypt(password,pw_hash[:2])
23  if new_pw_hash != pw_hash:
24  warn("new_pw_hash", repr(new_pw_hash), repr(pw_hash))
25  return 0
26  return 1
27 
28 
29 def encode_digest(digest):
30  hexrep = []
31  for c in digest:
32  n = (ord(c) >> 4) & 0xf
33  hexrep.append(hex(n)[-1])
34  n = ord(c) & 0xf
35  hexrep.append(hex(n)[-1])
36  return ''.join(hexrep)
37 
38 def decode_digest(digest):
39  code = []
40  for n in range(0, len(digest), 2):
41  a = chr(string.atoi(digest[n:n+2], 16))
42  code.append(a)
43  return string.join(code, '')
44 
45 
46 
47 
48 def mungePassword(password):
49  import zlib
50  mpw = zlib.compress(password)
51 
52  mpw = encode_digest(mpw)
53 
54  mpw = list(mpw)
55  mpw.reverse()
56  mpw = string.join(mpw, '')
57  return mpw
58 
59 def unmungePassword(mpassword):
60  import zlib
61 
62  mpassword = list(mpassword)
63  mpassword.reverse()
64  mpassword = string.join(mpassword, '')
65 
66  mpassword = decode_digest(mpassword)
67 
68  password = zlib.decompress(mpassword)
69  return password
70 
71 
72 def test():
73  pass
74 
75 def usage(progname):
76  print __doc__ % vars()
77 
78 def main(argv, stdout, environ):
79  progname = argv[0]
80  optlist, args = getopt.getopt(argv[1:], "", ["help", "test", "debug"])
81 
82  testflag = 0
83  if len(args) == 0:
84  usage(progname)
85  return
86  for (field, val) in optlist:
87  if field == "--help":
88  usage(progname)
89  return
90  elif field == "--debug":
91  debugfull()
92  elif field == "--test":
93  testflag = 1
94 
95  if testflag:
96  test()
97  return
98 
99 
100 if __name__ == "__main__":
101  main(sys.argv, sys.stdout, os.environ)
def mungePassword(password)
Definition: pwauth.py:48
def decode_digest(digest)
Definition: pwauth.py:38
def checkPassword(password, pw_hash)
Definition: pwauth.py:21
def main(argv, stdout, environ)
Definition: pwauth.py:78
def encode_digest(digest)
Definition: pwauth.py:29
def cryptPassword(password)
Definition: pwauth.py:15
def unmungePassword(mpassword)
Definition: pwauth.py:59
def usage(progname)
Definition: pwauth.py:75


webui
Author(s): Scott Hassan
autogenerated on Mon Jun 10 2019 15:51:24