question

Akarsh jain avatar image
Akarsh jain asked

Why playfab not accepting Username(A-Z,a-z,0-9)?

// i am basically trying to use Username as UserId cause username in playfab needs to be unique and also it can't be changed 


// Generating Username as

public static string GetRandomUserId(int _length){
        string _id = string.Empty;
        for (int i = 0; i < _length; i++)
        {
            int random = UnityEngine.Random.Range(0,36);
            if (random < 26){
                _id += (char)(random + 65); 
            }else{
                _id += (random - 26).ToString();
            }
        }
        Debug.Log($"UserId = {_id}");
        return _id;
    }

    public void OnRegisterButton() {

        // Setting USER_ID String to random 7 digit string
        string USER_ID = RandomIdGenerator.GetRandomUserId(7);
        // running user built in Register Func.
        RegisterUser(USER_ID, EmailInput.Text, PasswordInput.Text);
    }



void RegisterUser(string _Userid, string _email, string _password){
        RegisterPlayFabUserRequest request = new RegisterPlayFabUserRequest();
        
        request.RequireBothUsernameAndEmail = true;
        
        request.Username = _Userid;// Can't be changed
        request.Email = _email;// can be updated
        request.Password = _password;// can be reset

        PlayFabClientAPI.RegisterPlayFabUser(request, OnRegisterSuccess, OnError);
    }
    

    void OnRegisterSuccess(RegisterPlayFabUserResult result){
        Debug.Log("User Registered");
    }

    void OnError(PlayfabError error){
        Debug.Log("error.ErrorMessage");
    }






10 |1200

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

1 Answer

·
Akarsh jain avatar image
Akarsh jain answered
//Hey Nevermind, it was some error maybe with my script or what i dont know but when i tried the same thing it worked.

 Actually i think it was solved when i removed the line  

=> request.RequireBothUsernameAndEmail = true;
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.