password cracking – How much entropy is needed for encrypting data locally?

I understand that, when storing data on the cloud or something else that might get leaked to the public, the security margin should be at least 128 bit, 256 bit should be used for data that should stay secure over 20-30 years.

If I use a storage mechanism (like WebStorageAPI) to store data of my application on the client, is it secure enough to use a key derived from the password of the user (about 40 bit entropy) to encrypt the data locally if a random person of the public got access to the unlocked device (like in university or in a café)?

The idea is, that the device could then generate a key that is used to encrypt the data that is stored online and encrypt it locally using the password of the user. This way the security of the data that is stored online does not depend on the strength of the password, only attacks with access to the device would be possible.
(It would be necessary to communicate that key between devices in a multi-device-setting, but let’s assume that this issue is already solved)