Locking a chest not working

I want to be able to look at a chest while holding a nametag with a password, crouch and right click, and lock the chest with that password.

I tried using /data to do the locking part but for some reason its not working

Continue to help post