[Zope-Checkins] CVS: Zope3/lib/python/Zope/Server/Authentication - UnixAuthentication.py:1.1.2.1 DictionaryAuthentication.py:1.1.2.2 IAuthentication.py:1.1.2.2

Stephan Richter srichter@cbu.edu
Wed, 3 Apr 2002 09:38:01 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/Server/Authentication
In directory cvs.zope.org:/tmp/cvs-serv20611/Authentication

Modified Files:
      Tag: Zope3-Server-Branch
	DictionaryAuthentication.py IAuthentication.py 
Added Files:
      Tag: Zope3-Server-Branch
	UnixAuthentication.py 
Log Message:
Okay, I just added rename functionality to the server, which means that the
new version of the FTP server handles now more commands than the old one!


=== Added File Zope3/lib/python/Zope/Server/Authentication/UnixAuthentication.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

$Id: UnixAuthentication.py,v 1.1.2.1 2002/04/03 14:37:28 srichter Exp $
"""
import crypt
import pwd

from IAuthentication import IAuthentication


class UnixAuthentication:
    """ """

    __implements__ = IAuthentication


    ############################################################
    # Implementation methods for interface
    # Zope.Server.Authentication.IAuthentication.

    def authenticate(self, username, password):
        'See Zope.Server.Authentication.IAuthentication.IAuthentication'
        try:
            info = pwd.getpwnam(username)
        except KeyError:
            return 0, 'No such user.'

        mangled = info[1]

        print mangled
        print password
        print crypt.crypt(password, mangled[:2])
        
        if crypt.crypt(password, mangled[:2]) == mangled:
            return 1, 'Login successful.'
        else:
            return 0, 'Password invalid.'                

    #
    ############################################################


    def __repr__ (self):
        return '<standard unix authorizer>'


=== Zope3/lib/python/Zope/Server/Authentication/DictionaryAuthentication.py 1.1.2.1 => 1.1.2.2 ===
 
 from IAuthentication import IAuthentication
-from SimpleUser import SimpleUser, AnonymousUser
+
 
 class DictionaryAuthentication:
     """ """
 
     __implements__ = IAuthentication
 
-    # See Zope.Server.Authentication.IAuthentication.IAuthentication
-    user_class = SimpleUser
-    anonymous_user = AnonymousUser
 
     def __init__(self, user_dict):
         self.user_dict = user_dict
@@ -38,11 +35,16 @@
     def authenticate(self, username, password):
         'See Zope.Server.Authentication.IAuthentication.IAuthentication'
 
-        if ( username in self.user_dict.keys() and
-             password == self.user_dict[username]):
-            return self.user_class(username)
+        if username not in self.user_dict.keys():
+            return 0, 'No such user.'
+        elif password == self.user_dict[username]:
+            return 1, 'Login successful.'
         else:
-            return self.anonymous_user
+            return 0, 'Password invalid.'
 
     #
     ############################################################
+
+
+    def __repr__ (self):
+        return '<standard dictionary authorizer>'


=== Zope3/lib/python/Zope/Server/Authentication/IAuthentication.py 1.1.2.1 => 1.1.2.2 ===
         """
 
-        return IUser
+        return Boolean, str("Message")