~dustin-spy/twisted/dustin

« back to all changes in this revision

Viewing changes to twisted/cred/util.py

  • Committer: glyph
  • Date: 2002-01-27 23:10:25 UTC
  • Revision ID: vcs-imports@canonical.com-20020127231025-6180b0f76c6aba84
Moved twisted.internet.passport into twisted.cred.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
# System Imports
 
3
import md5
 
4
import random
 
5
 
 
6
 
 
7
class Unauthorized(Exception):
 
8
    """An exception that is raised when unauthorized actions are attempted.
 
9
    """
 
10
 
 
11
 
 
12
def respond(challenge, password):
 
13
    """Respond to a challenge.
 
14
    This is useful for challenge/response authentication.
 
15
    """
 
16
    m = md5.new()
 
17
    m.update(password)
 
18
    hashedPassword = m.digest()
 
19
    m = md5.new()
 
20
    m.update(hashedPassword)
 
21
    m.update(challenge)
 
22
    doubleHashedPassword = m.digest()
 
23
    return doubleHashedPassword
 
24
 
 
25
def challenge():
 
26
    """I return some random data.
 
27
    """
 
28
    crap = ''
 
29
    for x in range(random.randrange(15,25)):
 
30
        crap = crap + chr(random.randint(65,90))
 
31
    crap = md5.new(crap).digest()
 
32
    return crap