Exemple #1
0
 def test_crypt(self):
     encoded = make_password('letmein', 'ab', 'crypt')
     self.assertEqual(encoded, 'crypt$$abN/qM.L/H8EQ')
     self.assertTrue(is_password_usable(encoded))
     self.assertTrue(check_password('letmein', encoded))
     self.assertFalse(check_password('letmeinz', encoded))
     self.assertEqual(identify_hasher(encoded).algorithm, "crypt")
Exemple #2
0
 def test_bcrypt(self):
     encoded = make_password('letmein', hasher='bcrypt')
     self.assertTrue(is_password_usable(encoded))
     self.assertTrue(encoded.startswith('bcrypt$'))
     self.assertTrue(check_password('letmein', encoded))
     self.assertFalse(check_password('letmeinz', encoded))
     self.assertEqual(identify_hasher(encoded).algorithm, "bcrypt")
Exemple #3
0
 def test_unsalted_md5(self):
     encoded = make_password('letmein', 'seasalt', 'unsalted_md5')
     self.assertEqual(encoded, '0d107d09f5bbe40cade3de5c71e9e9b7')
     self.assertTrue(is_password_usable(encoded))
     self.assertTrue(check_password('letmein', encoded))
     self.assertFalse(check_password('letmeinz', encoded))
     self.assertEqual(identify_hasher(encoded).algorithm, "unsalted_md5")
Exemple #4
0
 def test_md5(self):
     encoded = make_password('letmein', 'seasalt', 'md5')
     self.assertEqual(encoded, 
                      'md5$seasalt$f5531bef9f3687d0ccf0f617f0e25573')
     self.assertTrue(is_password_usable(encoded))
     self.assertTrue(check_password('letmein', encoded))
     self.assertFalse(check_password('letmeinz', encoded))
     self.assertEqual(identify_hasher(encoded).algorithm, "md5")
Exemple #5
0
    def test_sha1(self):
        encoded = make_password('letmein', 'seasalt', 'sha1')
        self.assertEqual(encoded, 
'sha1$seasalt$fec3530984afba6bade3347b7140d1a7da7da8c7')
        self.assertTrue(is_password_usable(encoded))
        self.assertTrue(check_password('letmein', encoded))
        self.assertFalse(check_password('letmeinz', encoded))
        self.assertEqual(identify_hasher(encoded).algorithm, "sha1")
Exemple #6
0
    def test_pkbdf2(self):
        encoded = make_password('letmein', 'seasalt', 'pbkdf2_sha256')
        self.assertEqual(encoded, 
'pbkdf2_sha256$10000$seasalt$FQCNpiZpTb0zub+HBsH6TOwyRxJ19FwvjbweatNmK/Y=')
        self.assertTrue(is_password_usable(encoded))
        self.assertTrue(check_password('letmein', encoded))
        self.assertFalse(check_password('letmeinz', encoded))
        self.assertEqual(identify_hasher(encoded).algorithm, "pbkdf2_sha256")
Exemple #7
0
 def test_unusable(self):
     encoded = make_password(None)
     self.assertFalse(is_password_usable(encoded))
     self.assertFalse(check_password(None, encoded))
     self.assertFalse(check_password(UNUSABLE_PASSWORD, encoded))
     self.assertFalse(check_password('', encoded))
     self.assertFalse(check_password('letmein', encoded))
     self.assertFalse(check_password('letmeinz', encoded))
     self.assertRaises(ValueError, identify_hasher, encoded)
Exemple #8
0
    def render(self, name, value, attrs):
        encoded = value

        if not is_password_usable(encoded):
            return "None"

        final_attrs = self.build_attrs(attrs)

        try:
            hasher = identify_hasher(encoded)
        except ValueError:
            summary = mark_safe("<strong>Invalid password format or unknown hashing algorithm.</strong>")
        else:
            summary = format_html_join('',
                                       "<strong>{0}</strong>: {1} ",
                                       ((ugettext(key), value)
                                        for key, value in hasher.safe_summary(encoded).items())
                                       )

        return format_html("<div{0}>{1}</div>", flatatt(final_attrs), summary)
Exemple #9
0
 def test_simple(self):
     encoded = make_password('letmein')
     self.assertTrue(encoded.startswith('pbkdf2_sha256$'))
     self.assertTrue(is_password_usable(encoded))
     self.assertTrue(check_password('letmein', encoded))
     self.assertFalse(check_password('letmeinz', encoded))
Exemple #10
0
 def has_usable_password(self):
     return is_password_usable(self.password)