MCPcopy Create free account
hub / github.com/LUX-Core/lux / ChangeWalletPassphrase

Method ChangeWalletPassphrase

src/wallet.cpp:470–514  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

468}
469
470bool CWallet::ChangeWalletPassphrase(const SecureString& strOldWalletPassphrase, const SecureString& strNewWalletPassphrase)
471{
472 bool fWasLocked = IsLocked();
473 SecureString strOldWalletPassphraseFinal = strOldWalletPassphrase;
474
475 {
476 LOCK(cs_wallet);
477 Lock();
478
479 CCrypter crypter;
480 CKeyingMaterial _vMasterKey;
481 for (MasterKeyMap::value_type& pMasterKey : mapMasterKeys) {
482 if (!crypter.SetKeyFromPassphrase(strOldWalletPassphraseFinal, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
483 return false;
484 if (!crypter.Decrypt(pMasterKey.second.vchCryptedKey, _vMasterKey))
485 return false;
486 if (CCryptoKeyStore::Unlock(_vMasterKey)) {
487 int64_t nStartTime = GetTimeMillis();
488 crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod);
489 pMasterKey.second.nDeriveIterations = pMasterKey.second.nDeriveIterations * (100 / ((double)(GetTimeMillis() - nStartTime)));
490
491 nStartTime = GetTimeMillis();
492 crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod);
493 pMasterKey.second.nDeriveIterations = (pMasterKey.second.nDeriveIterations + pMasterKey.second.nDeriveIterations * 100 / ((double)(GetTimeMillis() - nStartTime))) / 2;
494
495 if (pMasterKey.second.nDeriveIterations < 25000)
496 pMasterKey.second.nDeriveIterations = 25000;
497
498 LogPrintf("Wallet passphrase changed to an nDeriveIterations of %i\n", pMasterKey.second.nDeriveIterations);
499
500 if (!crypter.SetKeyFromPassphrase(strNewWalletPassphrase, pMasterKey.second.vchSalt, pMasterKey.second.nDeriveIterations, pMasterKey.second.nDerivationMethod))
501 return false;
502 if (!crypter.Encrypt(_vMasterKey, pMasterKey.second.vchCryptedKey))
503 return false;
504 CWalletDB(strWalletFile).WriteMasterKey(pMasterKey.first, pMasterKey.second);
505 if (fWasLocked)
506 Lock();
507
508 return true;
509 }
510 }
511 }
512
513 return false;
514}
515
516void CWallet::SetBestChain(const CBlockLocator& loc)
517{

Callers 2

walletpassphrasechangeFunction · 0.80
changePassphraseMethod · 0.80

Calls 6

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

Tested by

no test coverage detected