当前位置: 首页>>代码示例>>C++>>正文


C++ OTPassword::getPassword方法代码示例

本文整理汇总了C++中OTPassword::getPassword方法的典型用法代码示例。如果您正苦于以下问题:C++ OTPassword::getPassword方法的具体用法?C++ OTPassword::getPassword怎么用?C++ OTPassword::getPassword使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OTPassword的用法示例。


在下文中一共展示了OTPassword::getPassword方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: dlg

/**
 * Try to unlock the wallet.  If a passphrase is needed, a dialog is shown
 * until the correct one is entered or the user cancels the action.  In the
 * latter case, UnlockFailure is thrown.
 * @throws UnlockFailure if the user cancels the unlock.
 */
void
NMC_WalletUnlocker::unlock ()
{
  std::string pwd;

  qDebug () << "Trying to unlock the Namecoin wallet.";

  /* If we need a password, show the dialog.  */
  if (nc.needWalletPassphrase ())
    {
      OTPassword otPwd;

      MTDlgPassword dlg (nullptr, otPwd);
      dlg.setDisplay ("Your Namecoin wallet is locked.  For the operations to"
                      " proceed, please enter the passphrase to temporarily"
                      " unlock the wallet.");
      const int res = dlg.exec ();

      /* Return code is 0 for cancel button or closing the window.
         It is 1 in case of ok.  */
      if (res == 0)
        {
          qDebug () << "Wallet unlock was cancelled.";
          throw UnlockFailure("Wallet unlock was cancelled.");
        }

      dlg.extractPassword ();
      pwd = otPwd.getPassword ();
    }

  /* Now try to unlock.  If the passphrase is wrong, retry by a tail-recursive
     call to unlock().  */
  try
    {
      unlocker.unlock (pwd);
      qDebug () << "Unlock successful (or not necessary).";
    }
  catch (const nmcrpc::NamecoinInterface::UnlockFailure& exc)
    {
      qDebug () << "Wrong passphrase, retrying.";
      unlock ();
    }
  catch (const nmcrpc::JsonRpc::RpcError& exc)
    {
      qDebug () << "NMC RPC Error " << exc.getErrorCode ()
                << ": " << exc.getErrorMessage ().c_str ();
    }
  catch (const std::exception& exc)
    {
      qDebug () << "Error: " << exc.what ();
    }
}
开发者ID:Paul4,项目名称:Moneychanger,代码行数:58,代码来源:Namecoin.cpp

示例2: if

OTPassword::OTPassword(const OTPassword & rhs)
:	m_nPasswordSize(0),
    m_bIsText(rhs.isPassword()),
    m_bIsBinary(rhs.isMemory()),
    m_bIsPageLocked(false),
    m_theBlockSize(rhs.m_theBlockSize) // The buffer has this size+1 as its static size.
{
    if (m_bIsText)
    {
        m_szPassword[0] = '\0';
        setPassword(rhs.getPassword(), rhs.getPasswordSize());
    }
    else if (m_bIsBinary)
    {
        setMemory(rhs.getMemory(), rhs.getMemorySize());
    }
}
开发者ID:DocMerlin,项目名称:Open-Transactions,代码行数:17,代码来源:OTPassword.cpp

示例3: Compare

bool OTPassword::Compare(OTPassword & rhs) const
{
    OT_ASSERT(this->isPassword() || this->isMemory());
    OT_ASSERT(rhs.isPassword()   || rhs.isMemory());
    
    if (this->isPassword() && !rhs.isPassword())
        return false;
    if (this->isMemory() && !rhs.isMemory())
        return false;
    
    const int nThisSize = this->isPassword() ? this->getPasswordSize() : this->getMemorySize();
    const int nRhsSize  = rhs.isPassword()   ? rhs.getPasswordSize()   : rhs.getMemorySize();
    
    if (nThisSize != nRhsSize)
        return false;
    
    if (0 == memcmp(this->isPassword() ? this->getPassword()   : this->getMemory(), 
                    rhs.isPassword()   ? rhs.getPassword()     : rhs.getMemory(), 
                    rhs.isPassword()   ? rhs.getPasswordSize() : rhs.getMemorySize()) )
        return true;
    
    return false;
}
开发者ID:DocMerlin,项目名称:Open-Transactions,代码行数:23,代码来源:OTPassword.cpp

示例4: GetMasterPassword


//.........这里部分代码省略.........
		// This time we DEFINITELY force the user input, since we already played our hand.
		// If the master key was still in memory we would have returned already, above.
		// Then we tried to find it on the keyring and we couldn't find it, so now we have
		// to actually ask the user to enter it.
		//

		std::string default_password(OT_DEFAULT_PASSWORD); // default password
		OTPassword passwordDefault; passwordDefault.zeroMemory(); passwordDefault.setPassword(default_password.c_str(),static_cast<int>(default_password.length()));

		OTPassword passUserInput;  passUserInput.zeroMemory(); // text mode.
		OTPasswordData  thePWData(str_display.c_str(), &passUserInput, this); // these pointers are only passed in the case where it's for a master key.
//      OTLog::vOutput(2, "*********Begin OTCachedKey::GetMasterPassword: Calling souped-up password cb...\n * *  * *  * *  * *  * ");
		// -----------------------------------------------------------------------


		// It's possible this is the first time this is happening, and the master key 
		// hasn't even been generated yet. In which case, we generate it here...
		//
		bool bGenerated = m_pSymmetricKey->IsGenerated();

		if (!bGenerated) // This Symmetric Key hasn't been generated before....
		{

			if (!OTAsymmetricKey::GetPasswordCallback()(NULL, 0, bVerifyTwice ? 1 : 0, static_cast<void *>(&thePWData)))
			{
				OTLog::vError("%s: Failed to get password from user!", __FUNCTION__);
				return false;
			}


			// If the length of the user supplied password is less than 4 characters long, we are going to use the default password!
			bool bUsingDefaultPassword = false;
			{
				if (4 > std::string(passUserInput.getPassword()).length())
				{
					OTLog::vOutput(0, "\n Password entered was less than 4 characters long! This is NOT secure!!\n"
						"... Assuming password is for testing only... setting to default password: %s \n",
						OT_DEFAULT_PASSWORD);
					bUsingDefaultPassword = true;
				}
			}

//          OTLog::vOutput(0, "%s: Calling m_pSymmetricKey->GenerateKey()...\n", szFunc);

			bGenerated = m_pSymmetricKey->GenerateKey(bUsingDefaultPassword ? passwordDefault : passUserInput, &pDerivedKey); // derived key is optional here.
			//
			// Note: since I passed &pDerivedKey in the above call, then **I** am responsible to
			// check it for NULL, and delete it if there's something there!
			//
			if (NULL != pDerivedKey)
				theDerivedAngel.SetCleanupTarget(*pDerivedKey);
			else
				OTLog::vError("%s: FYI: Derived key is still NULL after calling OTSymmetricKey::GenerateKey.\n");

//          OTLog::vOutput(0, "%s: Finished calling m_pSymmetricKey->GenerateKey()...\n", szFunc);
		}
		else // m_pSymmetricKey->IsGenerated() == true. (Symmetric Key is already generated.)
		{
			// -------------------------------------------------------------------------------------------------
			// Generate derived key from passphrase.
			//
			// We generate the derived key here so that GetRawKeyFromPassphrase() call (below)
			// works with it being passed in. (Because the above call to GenerateKey also grabs
			// a copy of the derived key and passes it in below to the same GetRawKeyFromPassphrase.)
			//
			// So WHY are we keeping a copy of the derived key through these calls? Otherwise they
开发者ID:9cat,项目名称:Open-Transactions,代码行数:67,代码来源:OTCachedKey.cpp


注:本文中的OTPassword::getPassword方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。