Features
Games
Add-ons
Docs
Pricing
Forums
Blog
Log in
Sign Up

Features

Games

Add-ons

Docs

Pricing

Support

Blog

Log in

Sign Up

  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Ideas
    • Articles
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
avatar image
Question by nigelbess · Jan 12 at 03:08 AM ·

How to Check if Username is Available- Unity C#

I made a script with the PlayFab API that checks if a username is available. My approach seems really dirty to me, So I'm wondering if there is a better way.

And how can I set this up so that CheckUser() returns a bool?

public static void CheckUser(string username)

{

string password = GameFunctions.RandomString (16); //generates a 16 digit random string

LoginWithPlayFabRequest request = new LoginWithPlayFabRequest ()

{

Username = username,

Password = password,

};

PlayFabClientAPI.LoginWithPlayFab (request, OnCheckUserStub, OnCheckUser);

}

static void OnCheckUserStub(LoginResult result)

{

//this method is a placeholder and should never be called

}

static void OnCheckUser(PlayFabError error)

{

if (error.ToString().Contains ("AccountNotFound"))

{

Debug.Log ("available");

} else

{

Debug.Log ("taken");

}

}

Comment

People who like this

0 Show 0
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Brendan · Jan 12 at 03:10 AM

What's the intended use case? If the idea is that you want to display an "available" next to the input field and check every time the player types, that's not going to work, as you be generating a huge number of login calls per user - most of which would be rejected due to exceeding the limit on calls to that API endpoint.

If you're just trying to give the user feedback for their selected username when they're done typing, just use the RegisterPlayFabUser call - that'll also return the info you need.

Comment
nigelbess

People who like this

1 Show 5 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image nigelbess · Jan 12 at 03:39 AM 0
Share

Thank you for the fast reply!

This function gets called when the user clicks a button.

RegisterPlayFabUser isnt working for me.

I either give it all the required requests (username, password, etc.) and it successfully creates a new account. I just want to check the username, not create an account.

Or I only give it a username and it returns the "InvalidParams" error, which doesnt give me information I need.

Also, RegisterPlayFabUser is still a void, meaning I cant return a bool from it right?

avatar image Brendan ♦♦ nigelbess · Jan 12 at 03:45 AM 0
Share

I don't follow - what specifically is not working when you call RegisterPlayFabUser. In the case where that call succeeds, the return contains the Session Ticket for the user.

avatar image nigelbess Brendan ♦♦ · Jan 12 at 03:49 AM 0
Share

I dont want the user to have to input their password, email, etc when checking for username availability.

So if the username is available, I still dont want to register an account.

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • Follow this Question

    Answers Answers and Comments

    2 People are following this question.

    avatar image avatar image

    Tickets

    Need help with a confidential issue? We've got your back!

  • Create Ticket
  • View Open Tickets
  • Stay up-to-date with the latest from PlayFab:  
    Sign up for newsletter
    Engineers
    • Documentation
    • Tutorials
    • API Reference
    • SDKs
    • Usage Limits
    PLAYFAB
    • Features
    • Games
    • Add-ons
    • Pricing
    Support
    • Forums
    • Videos
    • File a Ticket
    • Service Health
    • Blog
    About
    • About
    • Jobs
    • Contact
    • Press Room
    • Privacy Policy
    • Terms of Service
    • Acceptable Use
    • Style Guide
     
     
    Sign Up

    ©2017 PlayFab, Inc.

    ©2016 PlayFab, Inc. All rights reserved. PlayFab® is a registered trademark of PlayFab, Inc. | Privacy | Terms | Acceptable Use
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Post an idea
    • Create an article
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Ideas
    • Articles
    • Users
    • Badges