Exemplo n.º 1
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(u'letmein', encoded))
        self.assertFalse(check_password('letmeinz', encoded))
Exemplo n.º 2
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(u'letmein', encoded))
        self.assertFalse(check_password('letmeinz', encoded))
Exemplo n.º 3
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(u'letmein', encoded))
     self.assertFalse(check_password('letmeinz', encoded))
Exemplo n.º 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(u'letmein', encoded))
     self.assertFalse(check_password('letmeinz', encoded))
Exemplo n.º 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(u'letmein', encoded))
     self.assertFalse(check_password('letmeinz', encoded))
Exemplo n.º 6
0
 def test_no_upgrade(self):
     encoded = make_password('letmein')
     state = {'upgraded': False}
     def setter():
         state['upgraded'] = True
     self.assertFalse(check_password('WRONG', encoded, setter))
     self.assertFalse(state['upgraded'])
Exemplo n.º 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(u'letmein', encoded))
     self.assertFalse(check_password('letmeinz', encoded))
Exemplo n.º 8
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(u'letmein', encoded))
     self.assertFalse(check_password('letmeinz', encoded))
Exemplo n.º 9
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(u'letmein', encoded))
     self.assertFalse(check_password('letmeinz', encoded))
Exemplo n.º 10
0
 def test_no_upgrade_on_incorrect_pass(self):
     self.assertEqual('pbkdf2_sha256', get_hasher('default').algorithm)
     for algo in ('sha1', 'md5'):
         encoded = make_password('letmein', hasher=algo)
         state = {'upgraded': False}
         def setter():
             state['upgraded'] = True
         self.assertFalse(check_password('WRONG', encoded, setter))
         self.assertFalse(state['upgraded'])
Exemplo n.º 11
0
    def test_no_upgrade(self):
        encoded = make_password('letmein')
        state = {'upgraded': False}

        def setter():
            state['upgraded'] = True

        self.assertFalse(check_password('WRONG', encoded, setter))
        self.assertFalse(state['upgraded'])
Exemplo n.º 12
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(u'letmein', encoded))
     self.assertFalse(check_password('letmeinz', encoded))
     # Alternate unsalted syntax
     alt_encoded = "md5$$%s" % encoded
     self.assertTrue(is_password_usable(alt_encoded))
     self.assertTrue(check_password(u'letmein', alt_encoded))
     self.assertFalse(check_password('letmeinz', alt_encoded))
Exemplo n.º 13
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(u'letmein', encoded))
     self.assertFalse(check_password('letmeinz', encoded))
     # Alternate unsalted syntax
     alt_encoded = "md5$$%s" % encoded
     self.assertTrue(is_password_usable(alt_encoded))
     self.assertTrue(check_password(u'letmein', alt_encoded))
     self.assertFalse(check_password('letmeinz', alt_encoded))
Exemplo n.º 14
0
    def test_no_upgrade_on_incorrect_pass(self):
        self.assertEqual('pbkdf2_sha256', get_hasher('default').algorithm)
        for algo in ('sha1', 'md5'):
            encoded = make_password('letmein', hasher=algo)
            state = {'upgraded': False}

            def setter():
                state['upgraded'] = True

            self.assertFalse(check_password('WRONG', encoded, setter))
            self.assertFalse(state['upgraded'])
Exemplo n.º 15
0
 def set_unusable_password(self):
     # Sets a value that will never be a valid hash
     self.password = make_password(None)
Exemplo n.º 16
0
 def set_password(self, raw_password):
     self.password = make_password(raw_password)
Exemplo n.º 17
0
 def set_password(self, plaintext):
     self.password = make_password(plaintext)
Exemplo n.º 18
0
 def doit():
     make_password('letmein', hasher='lolcat')
Exemplo n.º 19
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(u'letmein', encoded))
     self.assertFalse(check_password('letmeinz', encoded))
Exemplo n.º 20
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(u'letmein', encoded))
     self.assertFalse(check_password('letmeinz', encoded))
Exemplo n.º 21
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(u'letmein', encoded))
     self.assertFalse(check_password('letmeinz', encoded))
Exemplo n.º 22
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(u'letmein', encoded))
     self.assertFalse(check_password('letmeinz', encoded))
Exemplo n.º 23
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(u'letmein', encoded))
     self.assertFalse(check_password('letmeinz', encoded))
Exemplo n.º 24
0
 def set_password(self, raw_password):
     self.password = make_password(raw_password)
Exemplo n.º 25
0
 def doit():
     make_password('letmein', hasher='lolcat')
Exemplo n.º 26
0
 def set_unusable_password(self):
     # Sets a value that will never be a valid hash
     self.password = make_password(None)
Exemplo n.º 27
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(u'letmein', encoded))
     self.assertFalse(check_password('letmeinz', encoded))