MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / ChangeWalletPassphrase

Method ChangeWalletPassphrase

src/wallet/wallet.cpp:431–475  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

429}
430
431bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase)
432{
433 bool fWasLocked = IsLocked();
434
435 {
436 LOCK(cs_wallet);
437 Lock();
438
439 CCrypter crypter;
440 CKeyingMaterial _vMasterKey;
441 for (MasterKeyMap::value_type& pMasterKey : mapMasterKeys)
442 {
443 if(!crypter.SetKeyFromPassphrase(strOldWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
444 return false;
445 if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, _vMasterKey))
446 return false;
447 if (CCryptoKeyStore::Unlock(_vMasterKey))
448 {
449 int64_t nStartTime = GetTimeMillis();
450 crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod);
451 pMasterKey.second.nDeriveIterations = static_cast<unsigned int>(pMasterKey.second.nDeriveIterations * (100 / ((double)(GetTimeMillis() - nStartTime))));
452
453 nStartTime = GetTimeMillis();
454 crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod);
455 pMasterKey.second.nDeriveIterations = (pMasterKey.second.nDeriveIterations + static_cast<unsigned int>(pMasterKey.second.nDeriveIterations * 100 / ((double)(GetTimeMillis() - nStartTime)))) / 2;
456
457 if (pMasterKey.second.nDeriveIterations < 25000)
458 pMasterKey.second.nDeriveIterations = 25000;
459
460 WalletLogPrintf("Wallet passphrase changed to an nDeriveIterations of %i\n", pMasterKey.second.nDeriveIterations);
461
462 if (!crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
463 return false;
464 if (!crypter.Encrypt(_vMasterKey, pMasterKey.second.vchCryptedKey))
465 return false;
466 WalletBatch(*database).WriteMasterKey(pMasterKey.first, pMasterKey.second);
467 if (fWasLocked)
468 Lock();
469 return true;
470 }
471 }
472 }
473
474 return false;
475}
476
477void CWallet::ChainStateFlushed(const CBlockLocator& loc)
478{

Callers 2

walletpassphrasechangeFunction · 0.80

Calls 6

GetTimeMillisFunction · 0.85
WalletBatchClass · 0.85
SetKeyFromPassphraseMethod · 0.80
WriteMasterKeyMethod · 0.80
DecryptMethod · 0.45
EncryptMethod · 0.45

Tested by

no test coverage detected