def receive_before_update(mapper, connection, target): target.password = bcrypt.generate_password_hash(target.password) target.api_key = urandom(40).encode('hex')