Exemplo n.º 1
0
def testHashPassword():
    """
    Verify that password hashing works.

    test_hash1 should not equal test_hash2.
    test_hash1 should equal real_hash1
    """
    test_password1 = 'password'
    test_password2 = 'passw0rd'
    test_salt = 'salt'

    real_hash = b'\xa4\xe0%\xeb\xe5:\xd4E\xbd\x9e\x82\xd9a\xe1\xe9M\xc8L\x07h\xe2;\x8b\x80SM\x92\xb2\x12w\xeb\x81'  # noqa
    test_hash1 = Bitwarden.hashPassword(test_password1, test_salt)
    test_hash2 = Bitwarden.hashPassword(test_password2, test_salt)

    assert test_hash1 == real_hash
    assert test_hash1 != test_hash2
Exemplo n.º 2
0
    def updateMasterKey(self, old_password, new_password):
        """
        This function updates the master key for the random encryption key. We
        want to preserve this random encryption key. So we will decrypt with
        the old key, then recrypt with the new key.

        Args:
            :param self: This user
            :param old_password: The old master password
            :param new_password: The new master password
        """
        enc_key = Bitwarden.decrypt(
            self.key, Bitwarden.makeKey(old_password, self.email), None)
        self.key = Bitwarden.encrypt(
            enc_key, Bitwarden.makeKey(new_password, self.email))

        self.password_hash = Bitwarden.hashPassword(new_password, self.email)
        self.security_stamp = funcs.generateSecureUUID()