question

gdbros avatar image
gdbros asked

How to make a password reset system using Playfab and a website? I am interested in using Weebly, or GitHub site.

Hello PF community,

So I'm developing a Multiplayer game on Unity and I'm using Photon and Playfab.

The problem I'm facing is that I cannot make a password reset system using Playfab. I have read through docs and everything but, it doesn't specify the steps taken to send the new password to Playfab from the website, where player enters the new password in so called 'form'.

I mean that I need an API to send messages to Playfab server right, but how I will do it, I have to use JS I know but I don't know how to apply in Weebly as they don't allow access to backend.

I was thinking to use GitHub site as I may make the back end there, but what to write the code, where to write the code, I really have no knowledge about that, as docs is not specific.

Please guide me to the correct procedure. It will be grateful.

Thanks for your time though.

apis
10 |1200

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

Citrus Yan avatar image
Citrus Yan answered

@GdBros

Sure, here is the sample code:

var PlayFab = require("./node_modules/playfab-sdk/Scripts/PlayFab/PlayFab");
var PlayFabAdmin = require("./node_modules/playfab-sdk/Scripts/PlayFab/PlayFabAdmin");

function CallAdminResetPasswordAPISample() {
    PlayFab.settings.titleId = ""; //title id of yours
    PlayFab.settings.developerSecretKey = ""; //secretkey of your title
    var resetPasswordRequest = {
        Password: "", // new password the player submitted
        Token:""      //token in the url
    };

    PlayFabAdmin.ResetPassword(resetPasswordRequest, resetPasswordCallback);
}
// reset password callback
function resetPasswordCallback(error, result) {
    if (result !== null) {
        console.log("Here are the results: \n");
        console.log(JSON.stringify(result));
    } else if (error !== null) {
        console.log("Something went wrong with your API call.");
        console.log("Here's some debug information:");
        console.log(CompileErrorReport(error));
    }
}

// Error report
function CompileErrorReport(error) {
    if (error == null)
        return "";
    var fullErrors = error.errorMessage;
    for (var paramName in error.errorDetails)
        for (var msgIdx in error.errorDetails[paramName])
            fullErrors += "\n" + paramName + ": " + error.errorDetails[paramName][msgIdx];
    return fullErrors;
}

// Make the actually admin call
CallAdminResetPasswordAPISample();

By the way, I am using NodeJS SDK since it's supposed to be executed from the back-end.

2 comments
10 |1200

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

Never Rage Dungeons and Dragons avatar image Never Rage Dungeons and Dragons commented ·

How do u get the token?

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Never Rage Dungeons and Dragons commented ·

The token is in the query string from the redirect URL, and will look something like what appears below:

https://www.example.com/?token=2346241B7C277796

You may use the following code to access if you're using PHP:

https://www.php.net/manual/en/reserved.variables.get.php

<?php

echo 'Hello ' . htmlspecialchars($_GET["token"]) . '!';

?>
0 Likes 0 ·
Citrus Yan avatar image
Citrus Yan answered

I am not so familiar with web development, however, I think the basic flow is the following:

1) The backend server get the form data (password) submitted by the player.

2) Combine it with the token in the URL to issue the ResetPassword API to PlayFab to reset the password for that player.

5 comments
10 |1200

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

gdbros avatar image gdbros commented ·

Thanks for your interest @Citrus Yan

But I can manage to get the form data, but after this, I'm not sure how to call the API.

I can call in this format

POST https://titleId.playfabapi.com/Admin/ResetPassword

but I still don't know where to put Request Body and exactly how. I may use FastAPI but IDK the exact syntax.

Please reply if you find something.

0 Likes 0 ·
gdbros avatar image gdbros commented ·

I may also use this syntax:

But I don't know what to call....

POST http://localhost:60464/api/student?age=15 HTTP/1.1
User-Agent: Fiddler
Host: localhost:60464
Content-Type: application/json
Content-Length: 13

{
  id:1,
  name:'Steve'
}
0 Likes 0 ·
Citrus Yan avatar image Citrus Yan gdbros commented ·

I assume that you are using Javascript, is that right? In that case, you can install the JavaScript SDK, which includes models, methods, an HTTP wrapper for sending and receiving web requests, and JSON serialization, PlayFab offers to interact with PlayFab APIs without getting down to the nitty-gritty, please take a look.

You may also find this JavaScript quickstart which helps you make your first API call in JavaScript helpful.

0 Likes 0 ·
gdbros avatar image gdbros Citrus Yan commented ·

Thanks for your information, but just one confusion. Can you just give a sample code that how I will call a certain functions like Resetpassword using JS??

A short example will be very helpful, although I will try more to understand the snippet provided in the docs....

0 Likes 0 ·
Show more comments
bbekec avatar image
bbekec answered

Hello, please help me. I am at this point and I am stuck. I successfully sent email, and direct player to login page with token. I uploaded PlayfabSdk to the website. I can call a javascript function to send parameters (new password and token) but there is no response from javascript if i call PlayFabAdminApi.ResetPassword.

Here is my code

<script type="text/javascript" src="/src/PlayFab/PlayFabAdminApi.js"></script>
<script type="text/javascript">
	function BilgileriGonder()
	{
			alert("geldi");
			PlayFab.settings.titleId = "myTitleId"; 
			PlayFab.settings.developerSecretKey = "mySecretKey";
			alert("geldi 2");
			var resetPasswordRequest = 
				{
					Password: document.getElementById("password").value, 
					Token: document.getElementById("token_").value    
				};
			alert(resetPasswordRequest.Token + " - " + resetPasswordRequest.Password);
			PlayFabAdminSDK.ResetPassword(resetPasswordRequest, resetPasswordCallback);
		}
		function resetPasswordCallback(error, result) 
		{
			alert("Geri Bildirim Geldi");
			if(result!=null)
			{
				alert("0 " +  result);
			}
			else
			{
				alert("1 " + result + " - " + error);
			}
		}
	</script>

Thanks

Edit: I finally managed to do it. The problem is external JavaScript path I think. I changed the path and i successfully recover password.

10 |1200

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

peterkallviks avatar image
peterkallviks answered

Here is a php code snippet that work for me:

echo '=============== START ===============';
        echo '<br>';




        $ch = curl_init();
        
        curl_setopt($ch, CURLOPT_URL, 'https://99999.playfabapi.com/Admin/ResetPassword?Password=lisalisa&Token=43D816F247CD3E10');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);


        $headers = array();
        $headers[] = 'X-Secretkey: xxxxxxxx';
        $headers[] = 'Content-Type: application/json';
        
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);


        $result = curl_exec($ch);


        if (curl_errno($ch)) {
            echo 'Error:' . curl_error($ch);
            echo '<br>';
        }
        else
        {
            echo '>>> WORKS <<<<';
            echo '<br>';
        }


        curl_close($ch);


        echo '>> ' . $result;
        echo '<br>';


        echo '=============== END ===============';
        echo '<br>';
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.

peterkallviks avatar image peterkallviks commented ·

Haven figured out yet how to protect the secret key, working on that.

0 Likes 0 ·
travis-1 avatar image
travis-1 answered

Hello,

For interest we build a password reset solution hosted on GITHUB.

https://github.com/Celestial-Games/PlayFabPasswordResetServer

Easy to configure and deploy

10 |1200

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

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.