Esempio n. 1
0
 def testSaltIsLongerThan8Characters(self):
     # Same password as in testNormal()
     password = "******"
     # Same salt as in testNormal(), but with added characters
     salt = "mYJd83wW9876543210"
     # Same result as in testNormal
     expectedResult = "$apr1$mYJd83wW$IO.6aK3G0d4mHxcImhPX50"
     result = md5_encode(password, salt)
     self.assertEqual(result, expectedResult)
 def mkhash(self, password):
     """ Returns a the hashed password as a string.
     """
     if self.algorithm == 'crypt':
         if len(password) > 8:
             self.logger.warning((
                 'Only the first 8 characters of the password are '
                 'used to form the password. The extra characters '
                 'will be discarded.'))
         return crypt.crypt(password, self.salt())
     elif self.algorithm == 'md5':
         return aprmd5.md5_encode(password, self.salt())
     elif self.algorithm == 'plain':
         return password
     elif self.algorithm == 'sha1':
         return b64encode(sha1(password).digest())
     else:
         raise ValueError(
             "The algorithm '%s' is not supported." % self.algorithm)
Esempio n. 3
0
 def testSaltIsEmptyString(self):
     password = "******"
     salt = ""
     expectedResult = "$apr1$$vGRl2mLvDG8pptkZ9Cyum."
     result = md5_encode(password, salt)
     self.assertEqual(result, expectedResult)
Esempio n. 4
0
 def testPasswordIsEmptyString(self):
     password = ""
     salt = "7n4Iu7Bq"
     expectedResult = "$apr1$7n4Iu7Bq$jsH1cRc.tyRPvJpZjxUjV."
     result = md5_encode(password, salt)
     self.assertEqual(result, expectedResult)
Esempio n. 5
0
 def testNormal(self):
     password = "******"
     salt = "mYJd83wW"
     expectedResult = "$apr1$mYJd83wW$IO.6aK3G0d4mHxcImhPX50"
     result = md5_encode(password, salt)
     self.assertEqual(result, expectedResult)