int CFrmLogin::SaveConf() { LOG_MODEL_DEBUG("Login", "CFrmLogin::SaveConf"); QSettings conf(CGlobalDir::Instance()->GetApplicationConfigureFile(), QSettings::IniFormat); int total = conf.value("Login/UserTotal", 0).toInt(); int i = 0; for(i = 0; i < total; i++) { if(conf.value("Login/UserName" + QString::number(i + 1)) == ui->cmbUser->currentText()) { conf.setValue("Login/LastUserNameIndex", i);//设置最后一次登录用户的索引 if(ui->chkLogin->isChecked() || ui->chkSave->isChecked()) { conf.setValue("Login/Password" + QString::number(i +1), EncryptPassword(ui->lnPassword->text())); } else conf.setValue("Login/Password" + QString::number(i +1), ""); return 0; } } if(i >= total) { conf.setValue("Login/UserTotal", total + 1); conf.setValue("Login/UserName" + QString::number(total +1), ui->cmbUser->currentText()); conf.setValue("Login/LastUserNameIndex", i);//设置最后一次登录用户的索引 if(ui->chkLogin->isChecked() || ui->chkSave->isChecked()) { conf.setValue("Login/Password" + QString::number(total +1), EncryptPassword(ui->lnPassword->text())); } else conf.setValue("Login/Password" + QString::number(total +1), ""); } return 0; }
LRESULT DominoDocConfigurationPage1::OnCbnSelchangeLibraryList(WORD /*wNotifyCode*/, WORD /*wID*/, HWND hWndCtl, BOOL& /*bHandled*/) { std::wstring user; std::wstring password; LRESULT index = ::SendMessage(hWndCtl, CB_GETCURSEL, 0, 0); if(CB_ERR != index) { LRESULT lResult = ::SendMessageW(hWndCtl, CB_GETLBTEXTLEN, index, 0); wchar_t* library = new wchar_t[lResult+1]; ::SendMessageW(hWndCtl, CB_GETLBTEXT, index, (LPARAM)library); wchar_t value[_MAX_PATH]; ::GetPrivateProfileStringW(library, L"userid", 0, value, _MAX_PATH, m_configFileName.c_str()); user = value; ::GetPrivateProfileStringW(library, L"password", 0, value, _MAX_PATH, m_configFileName.c_str()); password = EncryptPassword(false, value); delete [] library; } ::SetWindowTextW(GetDlgItem(IDC_USER).m_hWnd, user.c_str()); ::SetWindowTextW(GetDlgItem(IDC_PASSWORD).m_hWnd, password.c_str()); SetModified(TRUE); return 0; }
void Passwords::masterPassword() { QSettings settings; settings.beginGroup(QLatin1String("AutoComplete")); QString master = settings.value(QLatin1String("Master")).toString(); MasterPassword *dialog = new MasterPassword(this, master); if (dialog->exec() == QDialog::Accepted) { if ( master.length() > 0 && DecryptPassword(master) != dialog->txtOld->text()) { QMessageBox::warning(this, tr("Warning"), tr("Old password doesn't match the one you've typed!<br>New password has not been set.")); } else { if (dialog->txtNew->text() != dialog->txtConfirm->text()) { QMessageBox::warning(this, tr("Warning"), tr("Passwords do not match!<br>New password has not been set.")); } else { QMessageBox::warning(this, tr("Success"), tr("New master password has been set.")); settings.setValue(QLatin1String("Master"), EncryptPassword(dialog->txtNew->text())); } } } delete dialog; }
PasswordsModel::PasswordsModel(QObject *parent) : QAbstractTableModel(parent) { m_data.beginGroup("AutoComplete"); QString master = m_data.value(QLatin1String("Master")).toString(); if ( master.length() > 0) { QString pwd = QInputDialog::getText((QWidget*)parent, tr("Master Password"), tr("Type a master password:"******"Warning"), tr("Invalid password!<br>No information will be displayed.")); m_data.beginGroup(QLatin1String("fkgr")); } } }
void LoadCredentails(const std::wstring& library, std::wstring& userName, std::wstring& password) { std::wstring configFileName = (const wchar_t*)_bstr_t(MWGetApplicationPath().c_str()); configFileName.append(L"dominodoc.ini"); //char configFileName[_MAX_PATH] = {0}; //::sprintf(configFileName, "%sdominodoc.ini", TEST_PATH_MAKE_ABSOLUTE(L"Win32\\Debug\\")); wchar_t value[_MAX_PATH] = {0}; GetPrivateProfileStringW(library.c_str(), L"userid", NULL, value, _MAX_PATH, configFileName.c_str()); userName = value; ZeroMemory(value, sizeof(value)); GetPrivateProfileStringW(library.c_str(), L"password", NULL, value, _MAX_PATH, configFileName.c_str()); password = EncryptPassword(false, value); }
//============================================================================ // NMessageServer::AcceptConnection : Accept a connection. //---------------------------------------------------------------------------- NStatus NMessageServer::AcceptConnection(const NDictionary &/*serverInfo*/, const NDictionary &clientInfo, NEntityID clientID) { NString serverPassword, clientPassword; // Check the client state if ((NIndex) mClients.size() >= mMaxClients || clientID == kNEntityInvalid) return(kNErrBusy); // Check the password if (!mPassword.IsEmpty()) { clientPassword = clientInfo.GetValueString(kNMessagePasswordKey); serverPassword = EncryptPassword(mPassword); if (clientPassword != serverPassword) return(kNErrLocked); } return(kNoErr); }
void DominoDocConfigurationPage1::Apply() { SetModified(FALSE); std::wstring library; std::wstring user; std::wstring password; _bstr_t wndText; GetDlgItemText(IDC_LIBRARY_LIST, wndText.GetBSTR()); library = (const wchar_t*)wndText; GetDlgItemText(IDC_USER, wndText.GetBSTR()); user = (const wchar_t*)wndText; GetDlgItemText(IDC_PASSWORD, wndText.GetBSTR()); password = (const wchar_t*)wndText; DominoDoc::IApiPtr spDominoAPI; HRESULT hr = spDominoAPI.CreateInstance("DominoDoc.Api"); if(FAILED(hr)) throw std::exception("Failed to instantiate the Domino.Doc API in order to validate library settings.\nDomino.Doc Manager appears not to be installed on this computer."); spDominoAPI->SetHttpLogin(user.c_str(), password.c_str()); if(FAILED(hr)) throw std::exception("Failed to login to Domino.Doc server in order to validate library settings.\nPlease check the user name and password you have entered and try again."); DominoDoc::ILibraryPtr spLibrary = spDominoAPI->GetLibrary(library.c_str()); if(spLibrary == 0) throw std::exception("Failed to open library on Domino.Doc server in order to validate library settings.\nPlease check the library address you have entered and try again."); ::WritePrivateProfileStringW(library.c_str(), L"userid", user.c_str(), m_configFileName.c_str()); ::WritePrivateProfileStringW(library.c_str(), L"password", EncryptPassword(true, password).c_str(), m_configFileName.c_str()); LRESULT lResult = ::SendMessageW(GetDlgItem(IDC_LIBRARY_LIST).m_hWnd, CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)library.c_str()); if(CB_ERR == lResult) ::SendMessageW(GetDlgItem(IDC_LIBRARY_LIST).m_hWnd, CB_ADDSTRING, 0, (LPARAM)library.c_str()); }
void ExportPasswords(HWND hwndParent, int string_size, char* variables, stack_t** stacktop, extra_parameters* extra) { EXDLL_INIT(); char* source = new char[string_size]; if (popstring(source)) { MessageBoxA(hwndParent, "Missing parameter.", "ChromePasswords", MB_ICONERROR); pushstring(""); return; } char* dest = new char[string_size]; if (popstring(dest)) { MessageBoxA(hwndParent, "Missing parameter.", "ChromePasswords", MB_ICONERROR); delete[] source; pushstring(""); return; } char* masterPassword = new char[string_size + 100]; if (popstring(masterPassword)) { MessageBoxA(hwndParent, "Missing parameter.", "ChromePasswords", MB_ICONERROR); delete[] dest; delete[] source; pushstring(""); return; } char* endOfPassword; if (*masterPassword) { endOfPassword = masterPassword + strlen(masterPassword); strcpy_s(endOfPassword, 100, "UT^tQpa\"'Dort;huV&nq?-{@`+AYi}5=Hu[9bdqJQau82X1kw1"); } SQLite* webdata; try { webdata = new SQLite(source, SQLITE_OPEN_READONLY, NULL); } catch (int) { MessageBoxA(hwndParent, "Failed to open source database.", "ChromePasswords", MB_ICONERROR); SecureZeroMemory(masterPassword, string_size + 100); delete[] masterPassword; delete[] dest; delete[] source; return; } delete[] source; SQLite* portablepasswords; try { portablepasswords = new SQLite(dest, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); } catch (int) { MessageBoxA(hwndParent, "Failed to open destination database.", "ChromePasswords", MB_ICONERROR); webdata->Close(); delete webdata; SecureZeroMemory(masterPassword, string_size + 100); delete[] masterPassword; delete[] dest; return; } delete[] dest; SQLiteSTMT* statement; try { statement = portablepasswords->Prepare( "CREATE TABLE IF NOT EXISTS `logins` (`origin_url` VARCHAR NOT NULL, `username_element` VARCHAR, `username_value` VARCHAR, `password_element` VARCHAR, `password_value` BLOB, `submit_element` VARCHAR, `signon_realm` VARCHAR NOT NULL, UNIQUE (`origin_url`, `username_element`, `username_value`, `password_element`, `submit_element`, `signon_realm`))", -1, NULL); } catch (int) { MessageBoxA(hwndParent, "Failed to prepare create table statement.", "ChromePasswords", MB_ICONERROR); portablepasswords->Close(); delete portablepasswords; webdata->Close(); delete webdata; SecureZeroMemory(masterPassword, string_size + 100); delete[] masterPassword; return; } if (statement->Step() != SQLITE_DONE) { MessageBoxA(hwndParent, "Failed to create database table.", "ChromePasswords", MB_ICONERROR); statement->Close(); delete statement; portablepasswords->Close(); delete portablepasswords; webdata->Close(); delete webdata; SecureZeroMemory(masterPassword, string_size + 100); delete[] masterPassword; return; } statement->Close(); delete statement; try { statement = portablepasswords->Prepare("DELETE FROM `logins`", -1, NULL); } catch (int) { MessageBoxA(hwndParent, "Failed to prepare clear table statement.", "ChromePasswords", MB_ICONERROR); portablepasswords->Close(); delete portablepasswords; webdata->Close(); delete webdata; SecureZeroMemory(masterPassword, string_size + 100); delete[] masterPassword; return; } if (statement->Step() != SQLITE_DONE) { MessageBoxA(hwndParent, "Failed to clear database table.", "ChromePasswords", MB_ICONERROR); statement->Close(); delete statement; portablepasswords->Close(); delete portablepasswords; webdata->Close(); delete webdata; SecureZeroMemory(masterPassword, string_size + 100); delete[] masterPassword; return; } statement->Close(); delete statement; SQLiteSTMT* insert; try { insert = portablepasswords->Prepare( "INSERT INTO `logins` (`origin_url`, `username_element`, `username_value`, `password_element`, `password_value`, `submit_element`, `signon_realm`) VALUES (?, ?, ?, ?, ?, ?, ?)", -1, NULL); } catch (int) { MessageBoxA(hwndParent, "Failed to prepare insert password statement.", "ChromePasswords", MB_ICONERROR); portablepasswords->Close(); delete portablepasswords; webdata->Close(); delete webdata; SecureZeroMemory(masterPassword, string_size + 100); delete[] masterPassword; return; } try { statement = webdata->Prepare( "SELECT `origin_url`, `username_element`, `username_value`, `password_element`, `password_value`, `submit_element`, `signon_realm` FROM `logins`", -1, NULL); } catch (int) { MessageBoxA(hwndParent, "Failed to prepare dump passwords statement.", "ChromePasswords", MB_ICONERROR); insert->Close(); delete insert; portablepasswords->Close(); delete portablepasswords; webdata->Close(); delete webdata; SecureZeroMemory(masterPassword, string_size + 100); delete[] masterPassword; return; } int res; while ((res = statement->Step()) == SQLITE_ROW) { insert->Reset(); insert->ClearBindings(); const void* blob = statement->ColumnBlob(4); int blobLen = statement->ColumnBytes(4); const unsigned char* salt = statement->ColumnText(6); DATA_BLOB din; DATA_BLOB dout; din.cbData = blobLen; din.pbData = new byte[blobLen]; memcpy(din.pbData, blob, blobLen); if (!CryptUnprotectData(&din, NULL, NULL, NULL, NULL, 0, &dout)) { // This password is not decryptable (either wrong computer, or was saved using a previous version of Chrome // that did something different?). Skip it. //DWORD dw = GetLastError(); //LPVOID lpMsgBuf; //FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, dw, // MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, NULL); //MessageBox(NULL, (LPCWSTR)lpMsgBuf, L"ChromePasswords", MB_ICONWARNING); delete[] din.pbData; continue; } delete[] din.pbData; if (*masterPassword) { byte* encrypted = EncryptPassword(dout.pbData, &(dout.cbData), masterPassword, (char*)salt, hwndParent); SecureZeroMemory(dout.pbData, dout.cbData); LocalFree(dout.pbData); if (!encrypted) { continue; } insert->BindBlob(5, encrypted, dout.cbData, SQLITE_TRANSIENT); delete[] encrypted; } else { insert->BindBlob(5, dout.pbData, dout.cbData, SQLITE_TRANSIENT); SecureZeroMemory(dout.pbData, dout.cbData); LocalFree(dout.pbData); } for (int i = 0; i < 7; i += 1) { if (i != 4) { insert->Bind(i + 1, (const char*)statement->ColumnText(i), statement->ColumnBytes(i), SQLITE_TRANSIENT); } } if (insert->Step() != SQLITE_DONE) { MessageBoxA(hwndParent, "Failed to add password to table.", "ChromePasswords", MB_ICONERROR); insert->Close(); delete insert; statement->Close(); delete statement; portablepasswords->Close(); delete portablepasswords; webdata->Close(); delete webdata; SecureZeroMemory(masterPassword, string_size + 100); delete[] masterPassword; return; } } insert->Close(); delete insert; statement->Close(); delete statement; portablepasswords->Close(); delete portablepasswords; webdata->Close(); delete webdata; SecureZeroMemory(masterPassword, string_size + 100); delete[] masterPassword; if (res != SQLITE_DONE) { MessageBoxA(hwndParent, "Failed to finish iterating through results.", "ChromePasswords", MB_ICONERROR); } }
void WriteElement(PresetElement* pElement) { CDynamicArray <char> arLine, arTempString; AutoAlloc <BaseFile> pFile; Filename fn = GeGetC4DPath(C4D_PATH_PREFS) + String("ResEdit"); if (!pFile) return; String strNewName; Int32 n; for (n = 0; n < pElement->strName.GetLength(); n++) { UInt16 w = (UInt16)pElement->strName[n]; #if defined _WINDOWS if (('0' <= w && w <= '9') || ('A' <= w && w <= 'z') || w == ' ' || w == '_' || w == (UInt16)'�' || w == (UInt16)'�' || w == (UInt16)'�' || w == (UInt16)'�' || w == (UInt16)'�' || w == (UInt16)'�' || w == (UInt16)'�') #elif defined __MAC if (('0' <= w && w <= '9') || ('A' <= w && w <= 'z') || w == ' ' || w == '_' || w == (UInt16)'Š' || w == (UInt16)'š' || w == (UInt16)'Ÿ' || w == (UInt16)'€' || w == (UInt16)'…' || w == (UInt16)'†' || w == (UInt16)'§') #elif defined __LINUX if (('0' <= w && w <= '9') || ('A' <= w && w <= 'z') || w == ' ' || w == '_' || w == (UInt16)'ü' || w == (UInt16)'ö' || w == (UInt16)'ä' || w == (UInt16)'Ãœ' || w == (UInt16)'Ö' || w == (UInt16)'Ä' || w == (UInt16)'ß') #else #error Wrong operating system #endif strNewName += String(1, w); else strNewName += String(1, '_'); } if (!AssertPathExists(fn)) { GePrint(String("Could not create path ") + fn.GetString()); return; } if (GetPresetCrc(pElement) == pElement->ulCRC && (GeFExist(fn + (strNewName + ".prf")) || GeFExist(GeGetC4DPath(C4D_PATH_RESOURCE) + String("distribution") + (strNewName + ".prf")))) return; fn += (strNewName + ".prf"); if (!ForceOpenFileWrite(pFile, fn)) { GePrint(String("Could not write file ") + fn.GetString()); return; } AppendString(arLine, FILE_HEADER); WriteLine(arLine, pFile); AppendString(arLine, ORIG_PATH); AppendString(arLine, arTempString, pElement->strOrigin); WriteLine(arLine, pFile); AppendString(arLine, DEST_PATH); AppendString(arLine, arTempString, pElement->strDestination); WriteLine(arLine, pFile); AppendString(arLine, CREATE_ZIP); AppendString(arLine, pElement->bCreateZipFile ? "1" : "0"); WriteLine(arLine, pFile); Char *pszZipLevel = String::IntToString(pElement->lCreateZipCompressionLevel).GetCStringCopy(); if (pszZipLevel) { AppendString(arLine, CREATE_ZIP_COMPRESSION); AppendString(arLine, pszZipLevel); WriteLine(arLine, pFile); DeleteMem(pszZipLevel); } AppendString(arLine, CHECK_VERSION); AppendString(arLine, pElement->bCheckVersion ? "1" : "0"); WriteLine(arLine, pFile); AppendString(arLine, PARSE_SYMBOLS); AppendString(arLine, pElement->bParseSymbols ? "1" : "0"); WriteLine(arLine, pFile); AppendString(arLine, WRITE_BUILD); AppendString(arLine, pElement->bWriteBuildInfo ? "1" : "0"); WriteLine(arLine, pFile); AppendString(arLine, BATCH); AppendString(arLine, pElement->bBatch ? "1" : "0"); WriteLine(arLine, pFile); AppendString(arLine, REMOVE_SCC); AppendString(arLine, pElement->bRemoveSCC ? "1" : "0"); WriteLine(arLine, pFile); AppendString(arLine, PASSWORD); AppendString(arLine, arTempString, EncryptPassword(pElement->strPassword)); WriteLine(arLine, pFile); Int32 lFilterCount = pElement->arFilters.GetElementCount(); FilterElement** ppFilterElements = pElement->arFilters.GetArray()->GetArray(); for (n = 0; n < lFilterCount; n++) { AppendString(arLine, FILTER_STRING); AppendString(arLine, arTempString, ppFilterElements[n]->str); AppendString(arLine, " " FILTER_CONDITION); switch (ppFilterElements[n]->lCondition) { case FILTER_COND_FN_IS: AppendString(arLine, arTempString, W_FILTER_COND_FN_IS); break; case FILTER_COND_FN_EXT: AppendString(arLine, arTempString, W_FILTER_COND_FN_EXT); break; case FILTER_COND_PATH_CONTAINS: AppendString(arLine, arTempString, W_FILTER_COND_PATH_CONTAINS); break; case FILTER_COND_PATH_IS: AppendString(arLine, arTempString, W_FILTER_COND_PATH_IS); break; case FILTER_COND_DIRECTORY_IS: AppendString(arLine, arTempString, W_FILTER_COND_DIRECTORY_IS); break; default: DebugAssert(false); } AppendString(arLine, " " FILTER_ACTION); switch (ppFilterElements[n]->lAction) { case FILTER_ACTION_INCLUDE: AppendString(arLine, arTempString, W_FILTER_ACTION_INCLUDE); break; case FILTER_ACTION_EXCLUDE: AppendString(arLine, arTempString, W_FILTER_ACTION_EXCLUDE); break; case FILTER_ACTION_RENAME: AppendString(arLine, arTempString, W_FILTER_ACTION_RENAME); AppendString(arLine, " " FILTER_RENAME); AppendString(arLine, arTempString, ppFilterElements[n]->strRename); break; case FILTER_ACTION_COMPILE_INCL: AppendString(arLine, arTempString, W_FILTER_ACTION_COMPILE_INCL); break; case FILTER_ACTION_MOVE_TO: AppendString(arLine, arTempString, W_FILTER_ACTION_MOVE_TO); break; case FILTER_ACTION_FORCE_COPY: AppendString(arLine, arTempString, W_FILTER_ACTION_FORCE_COPY); break; case FILTER_ACTION_COMPILE_INCL_KILL: AppendString(arLine, arTempString, W_FILTER_ACTION_COMPILE_INCL_KILL); break; default: DebugAssert(false); } if (ppFilterElements[n]->bSetXBit) { AppendString(arLine, " " FILTER_FLAG); AppendString(arLine, arTempString, W_FILTER_FLAG_SET_XBIT); } WriteLine(arLine, pFile); } pFile->Close(); }
void CMigration::Migrate() { EncryptPassword(); StoreInstalledVersion(); InitialiseNewSettings(); }