Ejemplo n.º 1
0
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");
}
Ejemplo n.º 2
0
static void SaveUserPass (LoginDialogParam *pLoginParam, char *password)
{
    uint32_t cryptKey[4];
    memset(cryptKey, 0, sizeof(cryptKey));
    GetCryptKey(cryptKey, arrsize(cryptKey));

    plString theUser = pLoginParam->username;
    plString thePass = plString(password).Left(kMaxPasswordLength);

    // if the password field is the fake string then we've already
    // loaded the namePassHash from the file
    if (thePass.Compare(FAKE_PASS_STRING) != 0)
    {
        // Regex search for primary email domain
        std::vector<plString> match = theUser.RESearch("[^@]+@([^.]+\\.)*([^.]+)\\.[^.]+");

        if (match.empty() || match[2].CompareI("gametap") == 0) {
            plSHA1Checksum shasum(StrLen(password) * sizeof(password[0]), (uint8_t*)password);
            uint32_t* dest = reinterpret_cast<uint32_t*>(pLoginParam->namePassHash);
            const uint32_t* from = reinterpret_cast<const uint32_t*>(shasum.GetValue());

            // I blame eap for this ass shit
            dest[0] = hsToBE32(from[0]);
            dest[1] = hsToBE32(from[1]);
            dest[2] = hsToBE32(from[2]);
            dest[3] = hsToBE32(from[3]);
            dest[4] = hsToBE32(from[4]);
        }
        else
        {
            CryptHashPassword(theUser, thePass, pLoginParam->namePassHash);
        }
    }

    NetCommSetAccountUsernamePassword(theUser.ToWchar(), pLoginParam->namePassHash);

    // FIXME: Real OS detection
    NetCommSetAuthTokenAndOS(nil, L"win");

    plFileName loginDat = plFileName::Join(plFileSystem::GetInitPath(), "login.dat");
#ifndef PLASMA_EXTERNAL_RELEASE
    // internal builds can use the local init directory
    plFileName local("init\\login.dat");
    if (plFileInfo(local).Exists())
        loginDat = local;
#endif
    hsStream* stream = plEncryptedStream::OpenEncryptedFileWrite(loginDat, cryptKey);
    if (stream)
    {
        stream->Write(sizeof(cryptKey), cryptKey);
        stream->WriteSafeString(pLoginParam->username);
        stream->WriteBool(pLoginParam->remember);
        if (pLoginParam->remember)
            stream->Write(sizeof(pLoginParam->namePassHash), pLoginParam->namePassHash);
        stream->Close();
        delete stream;
    }
}