md5crypt.py
changeset 5774 0d792bceb25d
parent 5771 c077df1d0333
child 7879 9aae456abab5
equal deleted inserted replaced
5768:1e73a466aa69 5774:0d792bceb25d
     1 #########################################################
       
     2 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
       
     3 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
       
     4 #
       
     5 # This file is part of CubicWeb.
       
     6 #
       
     7 # CubicWeb is free software: you can redistribute it and/or modify it under the
       
     8 # terms of the GNU Lesser General Public License as published by the Free
       
     9 # Software Foundation, either version 2.1 of the License, or (at your option)
       
    10 # any later version.
       
    11 #
       
    12 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT
       
    13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
       
    14 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
       
    15 # details.
       
    16 #
       
    17 # You should have received a copy of the GNU Lesser General Public License along
       
    18 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
       
    19 """
       
    20 XXX clarify this header
       
    21 """
       
    22 # md5crypt.py
     1 # md5crypt.py
    23 #
     2 #
    24 # 0423.2000 by michal wallace http://www.sabren.com/
     3 # 0423.2000 by michal wallace http://www.sabren.com/
    25 # based on perl's Crypt::PasswdMD5 by Luis Munoz (lem@cantv.net)
     4 # based on perl's Crypt::PasswdMD5 by Luis Munoz (lem@cantv.net)
    26 # based on /usr/src/libcrypt/crypt.c from FreeBSD 2.2.5-RELEASE
     5 # based on /usr/src/libcrypt/crypt.c from FreeBSD 2.2.5-RELEASE
    34 #
    13 #
    35 # modification by logilab:
    14 # modification by logilab:
    36 # * remove usage of the string module
    15 # * remove usage of the string module
    37 # * don't include the magic string in the output string
    16 # * don't include the magic string in the output string
    38 #   for true crypt.crypt compatibility
    17 #   for true crypt.crypt compatibility
       
    18 # * use hashlib module instead of md5
    39 #########################################################
    19 #########################################################
    40 """md5crypt.py - Provides interoperable MD5-based crypt() function
    20 """md5crypt.py - Provides interoperable MD5-based crypt() function
    41 
    21 
    42 SYNOPSIS
    22 SYNOPSIS
    43 
    23 
    59 """
    39 """
    60 
    40 
    61 MAGIC = '$1$'                        # Magic string
    41 MAGIC = '$1$'                        # Magic string
    62 ITOA64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
    42 ITOA64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
    63 
    43 
    64 import md5
    44 import hashlib as md5
    65 
    45 
    66 def to64 (v, n):
    46 def to64 (v, n):
    67     ret = ''
    47     ret = ''
    68     while (n - 1 >= 0):
    48     while (n - 1 >= 0):
    69         n = n - 1
    49         n = n - 1