~landscape/zope3/newer-from-ztk

« back to all changes in this revision

Viewing changes to src/twisted/cred/util.py

  • Committer: Thomas Hervé
  • Date: 2009-07-08 13:52:04 UTC
  • Revision ID: thomas@canonical.com-20090708135204-df5eesrthifpylf8
Remove twisted copy

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
3
 
# See LICENSE for details.
4
 
 
5
 
 
6
 
"""
7
 
 
8
 
Utility functions for authorization.
9
 
 
10
 
These are currently for challenge-response shared secret authentication.
11
 
 
12
 
Maintainer: U{Glyph Lefkowitz<mailto:glyph@twistedmatrix.com>}
13
 
 
14
 
Stability: semi-stable
15
 
 
16
 
"""
17
 
 
18
 
# System Imports
19
 
import md5
20
 
import random
21
 
 
22
 
from twisted.cred.error import Unauthorized
23
 
 
24
 
def respond(challenge, password):
25
 
    """Respond to a challenge.
26
 
    This is useful for challenge/response authentication.
27
 
    """
28
 
    m = md5.new()
29
 
    m.update(password)
30
 
    hashedPassword = m.digest()
31
 
    m = md5.new()
32
 
    m.update(hashedPassword)
33
 
    m.update(challenge)
34
 
    doubleHashedPassword = m.digest()
35
 
    return doubleHashedPassword
36
 
 
37
 
def challenge():
38
 
    """I return some random data.
39
 
    """
40
 
    crap = ''
41
 
    for x in range(random.randrange(15,25)):
42
 
        crap = crap + chr(random.randint(65,90))
43
 
    crap = md5.new(crap).digest()
44
 
    return crap