[Zope3-checkins]
SVN: Zope3/branches/hdima-password-managers/src/zope/app/authentication/
Added basic password managers
Dmitry Vasiliev
dima at hlabs.spb.ru
Sat Sep 10 13:43:24 EDT 2005
Log message for revision 38440:
Added basic password managers
Changed:
U Zope3/branches/hdima-password-managers/src/zope/app/authentication/configure.zcml
U Zope3/branches/hdima-password-managers/src/zope/app/authentication/interfaces.py
A Zope3/branches/hdima-password-managers/src/zope/app/authentication/password.py
A Zope3/branches/hdima-password-managers/src/zope/app/authentication/password.zcml
U Zope3/branches/hdima-password-managers/src/zope/app/authentication/tests.py
-=-
Modified: Zope3/branches/hdima-password-managers/src/zope/app/authentication/configure.zcml
===================================================================
--- Zope3/branches/hdima-password-managers/src/zope/app/authentication/configure.zcml 2005-09-10 15:09:54 UTC (rev 38439)
+++ Zope3/branches/hdima-password-managers/src/zope/app/authentication/configure.zcml 2005-09-10 17:43:24 UTC (rev 38440)
@@ -61,6 +61,7 @@
</configure>
+ <include file="password.zcml" />
<include file="session.zcml" />
<include file="httpplugins.zcml" />
<include file="principalfolder.zcml" />
Modified: Zope3/branches/hdima-password-managers/src/zope/app/authentication/interfaces.py
===================================================================
--- Zope3/branches/hdima-password-managers/src/zope/app/authentication/interfaces.py 2005-09-10 15:09:54 UTC (rev 38439)
+++ Zope3/branches/hdima-password-managers/src/zope/app/authentication/interfaces.py 2005-09-10 17:43:24 UTC (rev 38440)
@@ -115,6 +115,15 @@
If the plugin cannot find information for the id, returns None.
"""
+class IPasswordManager(zope.interface.Interface):
+ """Password manager."""
+
+ def encodePassword(password):
+ """Return encoded data for the password."""
+
+ def checkPassword(storedPassword, password):
+ """Return whether the password coincide with the storedPassword."""
+
class IPrincipalInfo(zope.interface.Interface):
"""Minimal information about a principal."""
Added: Zope3/branches/hdima-password-managers/src/zope/app/authentication/password.py
===================================================================
--- Zope3/branches/hdima-password-managers/src/zope/app/authentication/password.py 2005-09-10 15:09:54 UTC (rev 38439)
+++ Zope3/branches/hdima-password-managers/src/zope/app/authentication/password.py 2005-09-10 17:43:24 UTC (rev 38440)
@@ -0,0 +1,97 @@
+##############################################################################
+#
+# Copyright (c) 2004 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.
+#
+##############################################################################
+"""Password managers
+
+$Id$
+"""
+
+import md5
+import sha
+
+from zope.interface import implements
+
+from zope.app.authentication.interfaces import IPasswordManager
+
+
+class PlainTextPasswordManager(object):
+ """Plain text password manager.
+
+ >>> from zope.interface.verify import verifyObject
+
+ >>> manager = PlainTextPasswordManager()
+ >>> verifyObject(IPasswordManager, manager)
+ True
+
+ >>> encoded = manager.encodePassword("password")
+ >>> encoded
+ 'password'
+ >>> manager.checkPassword(encoded, "password")
+ True
+ >>> manager.checkPassword(encoded, "bad")
+ False
+ """
+
+ implements(IPasswordManager)
+
+ def encodePassword(self, password):
+ return password
+
+ def checkPassword(self, storedPassword, password):
+ return storedPassword == self.encodePassword(password)
+
+class MD5PasswordManager(PlainTextPasswordManager):
+ """MD5 password manager.
+
+ >>> from zope.interface.verify import verifyObject
+
+ >>> manager = MD5PasswordManager()
+ >>> verifyObject(IPasswordManager, manager)
+ True
+
+ >>> encoded = manager.encodePassword("password")
+ >>> encoded
+ '5f4dcc3b5aa765d61d8327deb882cf99'
+ >>> manager.checkPassword(encoded, "password")
+ True
+ >>> manager.checkPassword(encoded, "bad")
+ False
+ """
+
+ implements(IPasswordManager)
+
+ def encodePassword(self, password):
+ return md5.new(password).hexdigest()
+
+class SHA1PasswordManager(PlainTextPasswordManager):
+ """SHA1 password manager.
+
+ >>> from zope.interface.verify import verifyObject
+
+ >>> manager = SHA1PasswordManager()
+ >>> verifyObject(IPasswordManager, manager)
+ True
+
+ >>> encoded = manager.encodePassword("password")
+ >>> encoded
+ '5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8'
+ >>> manager.checkPassword(encoded, "password")
+ True
+ >>> manager.checkPassword(encoded, "bad")
+ False
+ """
+
+ implements(IPasswordManager)
+
+ def encodePassword(self, password):
+ return sha.new(password).hexdigest()
Property changes on: Zope3/branches/hdima-password-managers/src/zope/app/authentication/password.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: Zope3/branches/hdima-password-managers/src/zope/app/authentication/password.zcml
===================================================================
--- Zope3/branches/hdima-password-managers/src/zope/app/authentication/password.zcml 2005-09-10 15:09:54 UTC (rev 38439)
+++ Zope3/branches/hdima-password-managers/src/zope/app/authentication/password.zcml 2005-09-10 17:43:24 UTC (rev 38440)
@@ -0,0 +1,42 @@
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ i18n_domain="zope">
+
+ <vocabulary
+ name="Password Manager Names"
+ factory="zope.app.component.vocabulary.UtilityVocabulary"
+ interface=".interfaces.IPasswordManager"
+ nameOnly="True"
+ />
+
+ <class class=".password.PlainTextPasswordManager">
+ <allow interface=".interfaces.IPasswordManager"/>
+ </class>
+
+ <utility
+ name="Plain Text"
+ provides=".interfaces.IPasswordManager"
+ factory=".password.PlainTextPasswordManager"
+ />
+
+ <class class=".password.MD5PasswordManager">
+ <allow interface=".interfaces.IPasswordManager"/>
+ </class>
+
+ <utility
+ name="MD5"
+ provides=".interfaces.IPasswordManager"
+ factory=".password.MD5PasswordManager"
+ />
+
+ <class class=".password.SHA1PasswordManager">
+ <allow interface=".interfaces.IPasswordManager"/>
+ </class>
+
+ <utility
+ name="SHA1"
+ provides=".interfaces.IPasswordManager"
+ factory=".password.SHA1PasswordManager"
+ />
+
+</configure>
Property changes on: Zope3/branches/hdima-password-managers/src/zope/app/authentication/password.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: Zope3/branches/hdima-password-managers/src/zope/app/authentication/tests.py
===================================================================
--- Zope3/branches/hdima-password-managers/src/zope/app/authentication/tests.py 2005-09-10 15:09:54 UTC (rev 38439)
+++ Zope3/branches/hdima-password-managers/src/zope/app/authentication/tests.py 2005-09-10 17:43:24 UTC (rev 38440)
@@ -40,6 +40,10 @@
from zope.publisher import base
from zope.app.authentication.session import SessionCredentialsPlugin
+from zope.app.authentication.interfaces import IPasswordManager
+from zope.app.authentication.password import PlainTextPasswordManager
+
+
class TestClientId(object):
implements(IClientId)
def __new__(cls, request):
@@ -93,15 +97,24 @@
self.assertEqual(plugin.logout(base.TestRequest('/')), False)
+def principalFolderSetUp(test):
+ placelesssetup.setUp()
+ ztapi.provideUtility(IPasswordManager,
+ PlainTextPasswordManager(), "Plain Text")
+
+
def test_suite():
return unittest.TestSuite((
doctest.DocTestSuite('zope.app.authentication.interfaces'),
+ doctest.DocTestSuite('zope.app.authentication.password'),
doctest.DocTestSuite('zope.app.authentication.generic'),
doctest.DocTestSuite('zope.app.authentication.httpplugins'),
doctest.DocTestSuite('zope.app.authentication.ftpplugins'),
- doctest.DocFileSuite('principalfolder.txt'),
+ doctest.DocFileSuite('principalfolder.txt',
+ setUp=principalFolderSetUp,
+ tearDown=placelesssetup.tearDown),
doctest.DocTestSuite('zope.app.authentication.principalfolder',
- setUp=placelesssetup.setUp,
+ setUp=principalFolderSetUp,
tearDown=placelesssetup.tearDown),
doctest.DocTestSuite('zope.app.authentication.idpicker'),
doctest.DocTestSuite('zope.app.authentication.session',
More information about the Zope3-Checkins
mailing list