/***************************************************************************** ** pfMacPasswordStore ** *****************************************************************************/ const plString pfMacPasswordStore::GetPassword(const plString& username) { plString service = GetServerDisplayName(); void* passwd = nullptr; uint32_t passwd_len = 0; if (SecKeychainFindGenericPassword(nullptr, service.GetSize(), service.c_str(), username.GetSize(), username.c_str(), &passwd_len, &passwd, nullptr) != errSecSuccess) { return plString::Null; } plString ret(reinterpret_cast<const char*>(passwd), size_t(passwd_len)); SecKeychainItemFreeContent(nullptr, passwd); return ret; }
bool pfMacPasswordStore::SetPassword(const plString& username, const plString& password) { plString service = GetServerDisplayName(); return SecKeychainAddGenericPassword(nullptr, service.GetSize(), service.c_str(), username.GetSize(), username.c_str(), password.GetSize(), password.c_str(), nullptr) == errSecSuccess; }
bool pfUnixPasswordStore::SetPassword(const ST::string& username, const ST::string& password) { GError *error = nullptr; ST::string server = GetServerDisplayName(); secret_password_store_sync(&pfPasswordStore_Schema, SECRET_COLLECTION_DEFAULT, ST::format("Myst Online Password for {}", server).c_str(), password.c_str(), nullptr, &error, "username", username.c_str(), "server", server.c_str(), nullptr); if (error) { g_error_free(error); return false; } else { return true; } }
/***************************************************************************** ** pfUnixPasswordStore ** *****************************************************************************/ ST::string pfUnixPasswordStore::GetPassword(const ST::string& username) { GError *error = nullptr; gchar *password = secret_password_lookup_sync(&pfPasswordStore_Schema, nullptr, &error, "username", username.c_str(), "server", GetServerDisplayName().c_str(), nullptr); ST::string result; if (error) { // Throw away the error and treat it as if no password was found... g_error_free(error); } else if (password) { result = ST::string::from_utf8(password); secret_password_free(password); } return result; }
static void LoadUserPass(LoginDialogParam *pLoginParam) { HKEY hKey; char accountName[kMaxAccountNameLength]; memset(accountName, 0, kMaxAccountNameLength); uint32_t rememberAccount = 0; DWORD acctLen = kMaxAccountNameLength, remLen = sizeof(rememberAccount); RegOpenKeyEx(HKEY_CURRENT_USER, plFormat("Software\\Cyan, Inc.\\{}\\{}", plProduct::LongName(), GetServerDisplayName()).c_str(), 0, KEY_QUERY_VALUE, &hKey); RegQueryValueEx(hKey, "LastAccountName", 0, NULL, (LPBYTE) &accountName, &acctLen); RegQueryValueEx(hKey, "RememberPassword", 0, NULL, (LPBYTE) &rememberAccount, &remLen); RegCloseKey(hKey); pLoginParam->remember = false; pLoginParam->username[0] = '\0'; if (acctLen > 0) strncpy(pLoginParam->username, accountName, kMaxAccountNameLength); pLoginParam->remember = (rememberAccount != 0); if (pLoginParam->remember && pLoginParam->username[0] != '\0') { pfPasswordStore* store = pfPasswordStore::Instance(); plString password = store->GetPassword(pLoginParam->username); if (!password.IsNull()) StoreHash(pLoginParam->username, password, pLoginParam); pLoginParam->focus = IDOK; } else if (pLoginParam->username[0] == '\0') pLoginParam->focus = IDC_URULOGIN_USERNAME; else pLoginParam->focus = IDC_URULOGIN_PASSWORD; }
static void SaveUserPass(LoginDialogParam *pLoginParam, char *password) { plString theUser = pLoginParam->username; plString thePass = password; HKEY hKey; RegCreateKeyEx(HKEY_CURRENT_USER, plFormat("Software\\Cyan, Inc.\\{}\\{}", plProduct::LongName(), GetServerDisplayName()).c_str(), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, NULL); RegSetValueEx(hKey, "LastAccountName", NULL, REG_SZ, (LPBYTE) pLoginParam->username, kMaxAccountNameLength); RegSetValueEx(hKey, "RememberPassword", NULL, REG_DWORD, (LPBYTE) &(pLoginParam->remember), sizeof(LPBYTE)); RegCloseKey(hKey); // If the password field is the fake string // then we've already loaded the hash. if (thePass.Compare(FAKE_PASS_STRING) != 0) { StoreHash(theUser, thePass, pLoginParam); pfPasswordStore* store = pfPasswordStore::Instance(); if (pLoginParam->remember) store->SetPassword(pLoginParam->username, thePass); else store->SetPassword(pLoginParam->username, plString::Null); } NetCommSetAccountUsernamePassword(theUser, pLoginParam->namePassHash); // FIXME: Real OS detection NetCommSetAuthTokenAndOS(nil, L"win"); }