Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase push Id: What characters can be inside?

Tags:

firebase

For an app I build, I want to use the ID generated by Firebase push as an email address local part. Since the dash (-) is not allowed as first character, I would like to replace it with another character.

This has to be reversible though. Therefore I want to know, which characters does the Firebase push ID consist of? So far I have seen:

  • alpha (a-z and A-Z and 0-9)
  • underscore (_)
  • dash (-)

Sample: -KD3rcGMuucRDjKOTK3O

  • Are there any other characters which might be contained in the ID?
  • Do firebase IDs always start with a dash?
like image 918
Makibo Avatar asked Mar 18 '16 13:03

Makibo


People also ask

How many characters is a uid?

A unique device identifier (UDID) is a 40-character string assigned to certain Apple devices including the iPhone, iPad and iPod Touch.

What is push id in Firebase?

If you're not familiar with Firebase's push IDs, they are the chronological, 20-character unique IDs generated when you write lists of data to Firebase from any of our client libraries.

Is Firebase id unique?

Firebase users have a fixed set of basic properties—a unique ID, a primary email address, a name and a photo URL—stored in the project's user database, that can be updated by the user (iOS, Android, web).

Which method will create a unique ID when the data is pushed in Firebase?

The Push Method The push() method will create a unique id when the data is pushed.


1 Answers

There are probably a lot of better ways to generate a unique email address than by using Firebase's push ids and then mangling them. That said, if you want to learn more about how Firebase generates its push ids, read this blog post: The 2^120 Ways to Ensure Unique Identifiers. It also explains why you should not rely on push ids to be unguessable/secure.

An important thing to realize from that post is that the first 8 characters of a push id contain an encoded timestamp, which is also the reason they always start with the same characters if you generate them close to each other.

The post also contains a link to a gist of the JavaScript code to generate a push id.

The set of characters that Firebase selects from is:

-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz;

As you can see the - is just the first character in this dictionary, which is the only reason the push ids (currently) all start with a -. At some point in the future they will start with a 0, then a 1, etc. If you take the code in the gist, you could calculate when each of those roll-overs happen.

Finally: I once wrote an answer on how to get the timestamp back from a push id. Doing so is not recommended, but it can be a fun experiment: Can you get the timestamp from a Firebase realtime database key?

like image 130
Frank van Puffelen Avatar answered Sep 19 '22 14:09

Frank van Puffelen