question

brendan avatar image
brendan asked

How to prevent duplicate login?

Vaion07281
started a topic on Fri, 03 July 2015 at 2:31 AM

Hi!

I use Photon Cloud and Playfab to my game

when PlayFabClientAPI.LoginWithPlayFab is success, will connect to photon cloud

then I try repeat login , it still success!!

how can i do?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

zaferokeanix avatar image
zaferokeanix answered

I made my own cheap solution for this, it's only downside is you have to manually logout these users who lost their devices, that shouldn't be problem if you have support system you can also check events to see if they are faking, you can wait couple days.

      private void OnGetUserDataSuccess(GetUserDataResult result)
      {
          string deviceId = SystemInfo.deviceName + "_" + SystemInfo.deviceModel + "_" + SystemInfo.deviceUniqueIdentifier;
          if (result.Data != null && result.Data.TryGetValue("DeviceID", out PlayFab.ClientModels.UserDataRecord userDataRecord))
          {
              string existingDeviceId = userDataRecord.Value;
              // If "SystemInfo.deviceUniqueIdentifier" is already stored and it's the same as the current value, do nothing
              if (existingDeviceId == deviceId)
              {
                  Debug.Log("Go For Second Confirmation");
                  Invoke("GetSecondUserDataDelayed", 5f);
                  return;
              }
              // If Logout Before
              else if (existingDeviceId == "LOGOUT")
              {
                  Debug.Log("Updating Device ID of Log-Out User");
              }
              // If "SystemInfo.deviceUniqueIdentifier" is already stored but it's different from the current value, update it
              else
              {
                  Debug.Log("Device ID has changed. Block User - " + existingDeviceId);
                  multipleloginScreen.SetActive(true);
                  return;
              }
          }
          // If "SystemInfo.deviceUniqueIdentifier" is not stored in user data, add it
          else
          {
              Debug.Log("Device ID is not stored in user data. Adding it.");
          }
          UpdateUserDataRequest request = new UpdateUserDataRequest()
          {
              Data = new Dictionary()
              {
                  { "DeviceID", deviceId }
              }
          };
          //Go For Second Confirmation Afterwards
          PlayFabClientAPI.UpdateUserData(request, OnUpdateUserDataSuccess, OnUpdateUserDataFailure);
      }

You call it with this after login

PlayFabClientAPI.GetUserData(new GetUserDataRequest(), OnGetUserDataSuccess, OnGetUserDataFailure);

Players can still log-in if two player click to log-in button in same time, to solve that you have to add another GetUserData with interval of 5 seconds, so when two players call UpdateUserData only one of them will stay and after 5 seconds you will get GetUserData and only one of them will pass the log-in screen.

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

wwwnewbninja avatar image wwwnewbninja commented ·

I updated my code so it works now, thanks for pointing out the redundant function. Also, your code is in individual lines, you should probably correct that.

Also, with your solution you could set a default logout value of 48 hours so it would automatically terminate the session after 48 hours to save having to have this support ticket system you suggested.

Hope this helps ;)

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.