- snip -
"Behind the scene" there is no balances. Balances are for humans. Wallets use transaction outputs.
- snip -
and if A user have
1000 balance in his wallet, then give wallet.dat file to B, then A changed his wallet password, B also changed password to some other, then what happen? Who can access and spend existing
1000 balance?
No.
Not "balance". Transaction outputs. Wallets track each output separately. A wallet is NOT an "account". It is software that manages individual outputs and private keys for you.
Wallets use transaction outputs. Transaction outputs are either unspent (UTXO), or spent.
What is UTXO?
UTXO is unspent transaction output.
and if A user have 1000 balance in his wallet, then give wallet.dat file to B, then A changed his wallet password, B also changed password to some other, then what happen? Who can access and spend existing 1000 balance?
BOTH
They BOTH still have the private keys for all the UTXO, so they BOTH can still spend the bitcoins.
Wallet does not have "balance", so when you change the password, you do NOT protect the balance. Wallet has private keys. Password is used to encrypt the private keys. Here is an analogy...
I have a file. I put a secret in the file. I give you a copy of the file. I encrypt my file with a password, and you encrypt your copy of the file with your password. Who can access my secret?
I can access my secret in my file with my password. You can access my secret in your file with your password. WE CAN BOTH STILL ACCESS MY SECRET.
Here is another analogy...
I have a file. I put a secret (secret_A) in the file. I give you a copy of the file. I add a new secret (secret_B) to my copy of the file. I encrypt my file with my password. You add a new secret (secret_C) to your file. You encrypt your file with your password. Who can access the secrets?
We can BOTH access secret_A, but ONLY I can access secret_B and ONLY YOU can access secret_C.
Wallet is the same. Wallet is a file. Wallet has secret keys (private keys). If I give you a copy of the file, then you can access all the private keys. If I add password to MY file, you can still access all the keys. If I add NEW KEYS to MY FILE AFTER I give you a copy, then you can STILL access the OLD keys, but you can NOT access the NEW keys.
Every payment that you receive with the wallet is separate UTXO. Wallet does NOT combine UTXO into "balance". It keeps track of each UTXO separately. If UTXO is received associated with private key that we BOTH have, then we BOTH can spend that UTXO (whichever gets confirmed first wins). If UTXO is received associated with private key that ONLY ONE of us has, then ONLY that ONE person can spend that UTXO.